Skip to content

Instantly share code, notes, and snippets.

@carlossanchezp
Created March 5, 2014 20:20
Show Gist options
  • Select an option

  • Save carlossanchezp/9375763 to your computer and use it in GitHub Desktop.

Select an option

Save carlossanchezp/9375763 to your computer and use it in GitHub Desktop.
Opción 1)
class DateRange
def initialize(from, to, step)
@from, @to, @step = from, to, step
end
def each
current = @from
while current < @to do
yield(current)
current += @step
end
end
end
dr = DateRange.new(1.year.ago, 1.week.from_now, 9.days)
dr.each { |dt| puts dt } ; nil
Opción 2)
curr=Date.today
end_date=curr + 1.year
step=2.weeks
while curr < end_date
puts curr
curr += step
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment