Skip to content

Instantly share code, notes, and snippets.

@ciscou
Created March 5, 2014 16:59
Show Gist options
  • Save ciscou/9371404 to your computer and use it in GitHub Desktop.
Save ciscou/9371404 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment