Module: Vitae::Delegators
- Included in:
- CV
- Defined in:
- lib/vitae/delegators.rb
Instance Method Summary collapse
Instance Method Details
#class_delegate(*args) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 |
# File 'lib/vitae/delegators.rb', line 3 def class_delegate *args target = args.pop[:to] rescue raise(ArgumentError, "Delegation needs a target. Supply an options hash with a :to key as the last argument (e.g. delegate :hello, :to => :greeter).") actions = args = (class << self; self; end) actions.each do |action| .send(:define_method, action) do |*args| send(target).send(action, *args) end end end |
#delegate(*args) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/vitae/delegators.rb', line 15 def delegate *args target = args.pop[:to] rescue raise(ArgumentError, "Delegation needs a target. Supply an options hash with a :to key as the last argument (e.g. delegate :hello, :to => :greeter).") actions = args actions.each do |action| define_method action do |*args| send(target).send(action, *args) end end end |