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 -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -