Method

A class of methods that have been encapsulated into objects by Object#method. The method itself (not its name) and the receiver are encapsulated as a pair. Unlike Proc objects, context is not preserved.

Differences with Proc: Method can only be created if there is a method to be fetched, but Proc can be created without any preparation. In light of this, Proc is suited for single uses, whereas Method is suited for repeated uses.

class Foo
  def foo(arg)
    "foo called with arg #{arg}"
  end
end
 
m = Foo.new.method(:foo)
 
p m             # => #<Method: Foo#foo>
p m.call(1)     # => "foo called with arg 1"

Superclass

Methods

call(arg ... )
call(arg ... ) { ... }

Starts a method encapsulated in a method object. Arguments and blocks are passed to the method as is.