Created
October 10, 2009 00:45
-
-
Save bbuckley/206482 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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