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
Comments
Post a Comment