def makeIteratorClass(&block)
Class.new do
def initialize init
@init = init
end
define_method :getNext do
@init = block.call @init
end
end
end
def test
c = makeIteratorClass {|x| x + 1}
o = c.new 10
p o.getNext
p o.getNext
p o.getNext
end
test
ZGVmIG1ha2VJdGVyYXRvckNsYXNzKCZibG9jaykKICBDbGFzcy5uZXcgZG8KICAgIGRlZiBpbml0aWFsaXplIGluaXQKICAgICAgQGluaXQgPSBpbml0CiAgICBlbmQKICAgIGRlZmluZV9tZXRob2QgOmdldE5leHQgZG8KICAgICAgQGluaXQgPSBibG9jay5jYWxsIEBpbml0CiAgICBlbmQKICBlbmQKZW5kCgpkZWYgdGVzdAogIGMgPSBtYWtlSXRlcmF0b3JDbGFzcyB7fHh8IHggKyAxfQogIG8gPSBjLm5ldyAxMAogIHAgby5nZXROZXh0CiAgcCBvLmdldE5leHQKICBwIG8uZ2V0TmV4dAplbmQKCnRlc3Q=