Skip to content

Instantly share code, notes, and snippets.

@bbuckley
Created October 10, 2009 00:45
Show Gist options
  • Save bbuckley/206482 to your computer and use it in GitHub Desktop.
Save bbuckley/206482 to your computer and use it in GitHub Desktop.
include Enumerable
def each
return Enumerator.new(self,:each) unless block_given?
yield 1
yield 2
end
puts each.inject(:+).inspect
puts each{|x| x * x}.inject(:+).inspect
def each_foo
return Enumerator.new(self,:each_foo) unless block_given?
yield 1
yield 2
end
puts each_foo.inject(:+).inspect
puts to_enum(:each_foo){|x| x * x}.inject(:+).inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment