background preloader

Block

Facebook Twitter

Is a block converted to a Proc object before yield? Hello!

Is a block converted to a Proc object before yield?

As you know, in Ruby, a block is not an object for some reasons, one of which is performance. def f yield end def g &blk blk.call end In g, a block is explicitly converted to a Proc object. What about in f? Is a block still converted to a Proc object implicitly? If it's not converted, I understand the performance issue. However, it's always converted to a Proc object, I don't understand why blocks improve performance just because they are not objects.