| Start |
|---|
| Introduction In Object Oriented Design, objects receive messages and reply to them. In Ruby, sending a message is calling a method and result of that method is the reply. In Ruby message passing is dynamic. When a message arrives rather than knowing exactly how to reply to it 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:
|
Message Passing Through Inheritance Chain To find a suitable method for It starts from After After Ruby checks all defined methods then it runs However if a method is defined Ruby uses defined version even if it is higher in the chain. For example if we send |
| Message Passing Through Module Composition Ruby moves up on ancestors chain of an object. This chain can contain both modules and classes. Same rules about moving up the chain apply to modules as well. |
| Interrupting Messages There are two ways to interrupt messages.
After interrupting messages, it is possible to:
Interrupting via Intercepting message and modifying it: Now let's imagine our data is "title:body" and we have to split them before calling Intercepting message and sending it to another object: |
Read Article
https://develop.horje.com/learn/1434/reference