Tutorial by Examples

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...
class Example def example_method :example end def subexample_method :example end def not_missed_method :example end def method_missing name return :example if name == :missing_example_method return :example if name == :missing_subexample_method ...
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. class Example end module Prepended def initialize *args return super :default if args.empty? super end end module Fi...
There are two ways to interrupt messages. Use method_missing to interrupt any non defined message. Define a method in middle of a chain to intercept the message After interrupting messages, it is possible to: Reply to them. Send them somewhere else. Modify the message or its result. ...

Page 1 of 1