fork download
  1. def makeIteratorClass(&block)
  2. Class.new do
  3. def initialize init
  4. @init = init
  5. end
  6. define_method :getNext do
  7. @init = block.call @init
  8. end
  9. end
  10. end
  11.  
  12. def test
  13. c = makeIteratorClass {|x| x + 1}
  14. o = c.new 10
  15. p o.getNext
  16. p o.getNext
  17. p o.getNext
  18. end
  19.  
  20. test
Success #stdin #stdout 0.03s 7460KB
stdin
Standard input is empty
stdout
11
12
13