3. Delegate
●
Easily expose contained objects’ public
methods as your own.
●
Useful with ActiveRecord associations
●
delegate :method_name, to: :target
4. Delegate
●
Multiple delegates to the same target are
allowed
●
delegate :method1, :method2, to: :target
●
Methods can be delegated to instance
variables, class variables, or constants
6. Options
●
:allow_nil
●
If the target is nil and does not respond to
the delegated method a NoMethodError is
raised
●
delegate :name, to: :profile, allow_nil: true
●
Returns nil
7. Options
●
delegate :name, to: :profile, prefix: true
●
Delegate methods are prefixed with the
name of the object being delegated to.
●
delegate :name, to: :client, prefix: :customer
●
Supply a custom prefix