You seem to be confusing blocks and procs. A block is not a ruby object. You cannot pass it like
foo(args, block)
The only way to pass it is foo(args){...}
or foo(args) do ... end
. However, in method definition, you can receive a block, convert it into a proc, and accept it as one of its arguments like this:
def foo(args, &block)
...
end
On the other hand, You can pass a proc object as an argument like
foo(args, proc)
There are several ways to create a proc object, and a literal that is close to the block literal is the lambda: ->{...}
, but it is different from the block syntax {...}
. Using this, you can do
foo(args, ->{...})
but not
foo(args, {...})
unless {...}
is a hash.