method(p1) public

Looks up the named method as a receiver in obj, returning a Method object (or raising NameError). The Method object acts as a closure in obj’s object instance, so instance variables and the value of self remain available.

   class Demo
     def initialize(n)
       @iv = n
     def hello()
       "Hello, @iv = #{@iv}"

   k = Demo.new(99)
   m = k.method(:hello)
   m.call   #=> "Hello, @iv = 99"

   l = Demo.new('Fred')
   m = l.method("hello")
   m.call   #=> "Hello, @iv = Fred"
Show source
Register or log in to add new notes.
October 4, 2010
1 thank

Bind the named method to the receiver

Binds the named method to the receiver, returning a Method object with access to the internals of the receiver, such as self and instance variables.