Class: Chassis::Delegation
- Inherits:
-
Module
- Object
- Module
- Chassis::Delegation
- Defined in:
- lib/chassis/delegate.rb
Instance Method Summary collapse
-
#initialize(*methods) ⇒ Delegation
constructor
A new instance of Delegation.
Constructor Details
#initialize(*methods) ⇒ Delegation
Returns a new instance of Delegation.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/chassis/delegate.rb', line 7 def initialize(*methods) = methods.last.is_a?(Hash) ? methods.pop : { } delegate = .fetch :to do fail ArgumentError, ":to not given" end methods.each do |method| define_method method do |*args, &block| object = send delegate fail DelegationError.new method, delegate unless object object.send(method, *args, &block) end end end |