In short, the Method object is “associated” with the object, so self points to this object when the method is call , and Proc does not have this behavior; self depends on the context in which Proc was created / invoked.
Anyway:
In your question, you said that “methods are not objects,” but you must be careful to distinguish between “method” and “ Method .
A "method" is a specific set of expressions that are named and placed in the method table of a particular class to simplify the search and execution later:
class Foo def my_method puts "line 1" puts "line 2" end end
The Method object (or similarly the UnboundMethod object) is a real Ruby object created by calling method / instance_method / etc. And passing the name of the "method" as an argument:
Foo.new.method(:my_method) # => #<Method: Foo#my_method> Foo.instance_method(:my_method) # => #<UnboundMethod: Foo#my_method>
A Proc object is a collection of expressions that are not given a name that you can save for later execution:
my_proc = Proc.new { 123 } my_proc.call
It may be useful to read the UnboundMethod documentation for UnboundMethod , Method and Proc . The RDoc pages list the various instance methods available for each type.
source share