This flow shows how calling method() on an object returns a Method object, which can be called later to run the original method.
Execution Sample
Ruby
class Greeter
def hello
"Hello!"endend
g = Greeter.new
m = g.method(:hello)
puts m.call
This code creates a Method object for the 'hello' method and calls it to print 'Hello!'.
Execution Table
Step
Action
Object State
Method Object
Output
1
Create Greeter instance g
g = #<Greeter:0x000...>
nil
nil
2
Call g.method(:hello)
g unchanged
Method object for hello bound to g
nil
3
Call m.call
g unchanged
Method object still exists
"Hello!" printed
4
End of program
No change
No change
Program ends
💡 Program ends after printing 'Hello!' from the Method object call
Variable Tracker
Variable
Start
After Step 1
After Step 2
After Step 3
Final
g
nil
#<Greeter:0x000...>
#<Greeter:0x000...>
#<Greeter:0x000...>
#<Greeter:0x000...>
m
nil
nil
Method(:hello) bound to g
Method(:hello) bound to g
Method(:hello) bound to g
Key Moments - 3 Insights
Why do we need to call .call on the Method object?
The method() call returns a Method object, which is like a saved reference to the method. To actually run the method, we must call .call on that Method object, as shown in step 3 of the execution_table.
Does calling method() execute the method immediately?
No, calling method() only returns a Method object without running the method. The method runs only when .call is used on that Method object, as seen between steps 2 and 3.
Is the original object changed after getting the Method object?
No, the original object remains unchanged throughout. The Method object just holds a reference to the method bound to that object, as shown in the Object State column.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 2. What does g.method(:hello) return?
Anil
BThe string 'Hello!'
CA Method object bound to g
DAn error
💡 Hint
Check the 'Method Object' column at step 2 in the execution_table.
At which step is the original 'hello' method actually executed?
AStep 1
BStep 3
CStep 2
DStep 4
💡 Hint
Look for when the output 'Hello!' is printed in the execution_table.
If we skip calling m.call, what will be the output?
Anil
BMethod object printed
CHello!
DError
💡 Hint
Refer to the Output column in the execution_table for step 2 and 3.
Concept Snapshot
Use method(:name) on an object to get a Method object.
Call .call on that Method object to run the original method.
method() does NOT run the method immediately.
The Method object keeps the method bound to the original object.
Useful to store or pass methods as objects.
Full Transcript
This visual trace shows how Ruby's method() works. First, an object is created from a class with a method. Calling method(:method_name) on the object returns a Method object, which is a reference to that method bound to the object. This does not run the method yet. To run it, you call .call on the Method object. The output appears only after .call is used. The original object remains unchanged throughout. This lets you save methods as objects and call them later.