Introduction
suggest changeIn object-oriented design, objects receive messages and reply to them. In Ruby, sending a message is calling a method, and the result of that method is the reply.
In Ruby, message passing is dynamic. When a message arrives, Ruby uses a predefined set of rules to find a method that can reply to it. We can use these rules to interrupt and reply to the message, send it to another object, or modify it, among other actions.
Each time an object receives a message, Ruby checks:
- Whether this object has a singleton class that can reply to this message.
- The object’s class, then that class’s ancestor chain.
- Each ancestor, one by one, for a method that can reply, moving up the chain.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents