How can I get a reference to a method?

前端 未结 4 512
花落未央
花落未央 2021-01-07 16:32

Is it possible in Ruby to get a reference to methods of an object ( I would like to know if this can be done without procs/lambdas ) , for example , consider the following c

4条回答
  •  情书的邮戳
    2021-01-07 17:05

    You can get a reference to the method by object.method(:method_name).

    Eg: To get a reference to system method.

    m = self.method(:system)
    m.call('ls')
    

提交回复
热议问题