Where does the block get saved.
I can make a block with contains the block but I think there is a better way
?
I think you don’t want to yield. You can capture the block like this:
def sum(initial_value = 0, &blk)
end
and then blk.call to execute the block, or use &blk to pass it to
another method. If I understood correctly, you want to map all
elements of the array to the result of passing each of them to the
block, then sum the result. If so, try something like this:
def sum(initial_value=0, &blk)
array.map(&blk).inject(initial_value, :+)
end