Possible Duplicate:
What’s this &block in Ruby? And how does it get passes in a method here?
I dont Understand the &block part, what does it do?
here is an example:
def method_missing(method_name, *args, &block)
@messages << method_name
@object.send method_name, *args, &block
end
Blocksgive you an opportunity to state a callback to pass on to a method.The
&is key here – like @pst mentioned, it “promotes” the block to a Proc and binds the Proc to the variable with the given name.With
&Without
&