-
-
Save headius/4f715ed9c5c9ecdca14f 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
#Enumerator.new {|y| y.yield 1}.each {break} | |
class Enumerator | |
def initialize(&b) | |
@g = Generator.new(&b) | |
end | |
def each | |
@g.each do |x| | |
yield x | |
end | |
end | |
end | |
class Generator | |
def initialize(&b) | |
@b = b | |
end | |
def each(&b) | |
y = Yielder.new(&b) | |
@b.call(y) | |
end | |
end | |
class Yielder | |
def initialize(&b) | |
@b = b | |
end | |
def yield(x) | |
@b.call(x) | |
end | |
end | |
Enumerator.new {|y| y.yield 1}.each {break} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment