I have this simple code to create a lazy array:
lazy_arr = Enumerator.new { |y|
i = 1
loop {
y << i
i+=1
}
}
p lazy_arr.take(5)
In official Ruby 1.9.3, the output [1,2,3,4,5]I want.
But in Rubinius it gives an error and says that I cannot find the Enumerator constant.
So, I looked through it and found the Enumerator defined in the module Enumerableinstead kernel, and when it is generated, it needs several arguments in brackets:
http://rubydoc.info/github/evanphx/rubinius/master/Enumerable/Enumerator
I tried changing Enumerator.newto Enumerable::Enumerator.newor include Enumerable, but does not work, because it needs more arguments.
How can I make an example above in Rubinius? Is there any way around code in both official and Rubinius?
source