Hello, good people of ruby-talk.
Iâ€™m trying to backport my code from Ruby 1.9 to Ruby 1.8.7 so that I can
profile it sanely with ruby-prof or zenprofile (neither of which works
sensibly under Ruby 1.9 as of now). Unfortunately, my code heavily uses
lazy-evaluated, nested Enumerator objects. What is the sanest way to
backport the following example so that it works more-or-less in the same
way under Ruby 1.8.7 as it does under Ruby 1.9?
def multiplier param
Enumerator.new do |yielder|
(1…10).each do |elem|
sleep 1 # simulates a long-running process
yielder.yield param * elem
multiplier(3).each do |e|
I think I need a proxy object that can emulate Ruby 1.9â€™s Enumerator.new
by taking a block and then being able to evaluate it in the original
calling placeâ€™s context (so that the â€˜paramâ€™ above is available to it
upon subsequent Enumerator#each calls), but my still-limited Ruby-fu
fails to come up with a solution for this.