I don't know any Ruby and am reading some documentationon it now. A doubt I have just after reading about using code blocks and the "yield" keyword is whether it is possible to pass more than one code block to a function, and use both at will from within the called function.
You can pass only one block at once but blocks are actually Proc
instances and you can pass as many instances you wish as parameters.
def mymethod(proc1, proc2, &block)
proc1.call
yield if block_given?
proc2.call
end
mymethod(Proc.new {}, Proc.new {}) do
# ...
end
However, it rarely makes sense.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With