method
method
![Moderate documentation Importance_2](https://d2vfyqvduarcvs.cloudfront.net/images/importance_2.png?1349367920)
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 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"
Register or
log in
to add new notes.
andersjanmyr -
October 4, 2010
![Default_avatar_30](https://www.gravatar.com/avatar/a792b764e783d1ccba4db7e4e1b846fd?size=30&default=http://apidock.com/images/default_avatar_30.png)
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.