Skip to content

Instantly share code, notes, and snippets.

@soulcutter
Last active September 4, 2015 16:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soulcutter/72f6843ed6785c4dd582 to your computer and use it in GitHub Desktop.
Save soulcutter/72f6843ed6785c4dd582 to your computer and use it in GitHub Desktop.
Each day
def days(range)
Enumerator.new do |yielder|
now = range.begin
begin
yielder << now if now <= range.end
end while (now = now + 1.day) <= range.end
end
end
days((Time.now - 3.days)..(Time.now)).each { |day| puts day }
# 09-02-2015 12:04:55
# 09-03-2015 12:04:55
# 09-04-2015 12:04:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment