Friday, April 12, 2013

Two different ways to execute a block

It is familiar that you will see yield being used when the block is anonymous and block.call being used when the block is explicit in the list of parameters for the method. Actually, you can use yield even when the block is explicitly passed to the method:

def foo(&block)
  yield
  block.call
end

foo { puts 'hi hey again' }