triangular_numbers = Enumerator.new do |yielder|
number = 0
count = 1
loop do
number += count
count += 1
yielder.yield number
end
end
5.times { print triangular_numbers.next, " " }
puts
I know you all have answers questions about this before.
I am trying to understand more about what going on
Am I right to say yielder is a parameter which is probably a hash or an array and yielder.yield number is basically pushing whatever number it is on to that array.
Also I seen people use yielder << number, i assume that you can also use yielder.push(number), will it do the same thing.
One other thing I like to know why the number is retaining its value.