Skip to content

Instantly share code, notes, and snippets.

@tigawa
Created February 26, 2013 22:50
Show Gist options
  • Save tigawa/5043102 to your computer and use it in GitHub Desktop.
Save tigawa/5043102 to your computer and use it in GitHub Desktop.
ruby 2.0 lazy
require 'date'
def each_fridays
friday = Date.new(2013,1,4)
loop do
yield friday
friday += 7
end
end
fridays = enum_for(:each_fridays)
# puts fridays.first 5
# fridays.select{|date| date.day == 13 }.first 5
puts fridays.lazy.select{|date| date.day == 13 }.first 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment