Skip to content

Instantly share code, notes, and snippets.

@headius
Created March 2, 2015 19:02
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 headius/4f715ed9c5c9ecdca14f to your computer and use it in GitHub Desktop.
Save headius/4f715ed9c5c9ecdca14f to your computer and use it in GitHub Desktop.
#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