What is the best way to convert a Ruby string range to a Range object

后端 未结 8 2204
一生所求
一生所求 2020-12-29 23:38

I have some Ruby code which takes dates on the command line in the format:

-d 20080101,20080201..20080229,20080301

I want to run for all da

8条回答
  •  星月不相逢
    2020-12-30 00:10

    assuming you want the range to iterate properly through months etc, try

    require 'date'
    
    ends = '20080201..20080229'.split('..').map{|d| Date.parse(d)}
    (ends[0]..ends[1]).each do |d|
      p d.day
    end
    

提交回复
热议问题