Skip to content

Instantly share code, notes, and snippets.

@taq
Created November 3, 2012 19:34
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 taq/4008422 to your computer and use it in GitHub Desktop.
Save taq/4008422 to your computer and use it in GitHub Desktop.
Natural numbers enumerator on Ruby 1.9.x
natural_numbers = Enumerator.new do |yielder|
number = 1
loop do
yielder.yield number
number += 1
end
end
p natural_numbers.select { |n| n.odd? }.take(5).to_a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment