obj.method(sym) â method
Instance Public methods
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | class Demo def initialize(n) @iv = n end def hello() "Hello, @iv = #{@iv}" end end 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" |
Please login to continue.