ruby - How to pass class method as parameter? -


i want pass class method function, how can that?

class   def a.test(data)     puts data   end end  def ps(fun)   fun(3) end  ps(a.test) 

you have use right getter receive method object:

class  def a.test(data)     puts data   end end  def ps(fun)   fun.call(3) end  ps(a.method(:test)) #=> 3 

the method method returns method-object, can executed call.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

spring cloud - How to configure SpringCloud Eureka instance to point to https on non standard port -

javascript - Bootstrap Popover: iOS Safari strange behaviour -