Is there are way to pass a method as a parameter without using a Proc object or block? The answers I've seen to similar questions rely on creating a Proc object.
def call_a_method_via_a_parameter( &some_method )
# ?? call some_method and pass it a parameter ??
end
def my_method( param )
puts param
end
call_a_method_via_a_parameter( &:my_method )
def bob(jeff)
puts "hi #{jeff}"
end
def mary(meth, params)
meth.call(params)
end
mary(method(:bob), 'yo')
=> hi yo
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