Module: Virtus::Delegate
Instance Method Summary collapse
Instance Method Details
#for(klass) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/virtus/delegate.rb', line 9 def for(klass) Module.new do attr_reader :_target, :_old_targets def initialize(target) @_target = target @_old_targets = [] end klass.attribute_set.each do |attribute| define_method(attribute.name) { _target.send(attribute.name) } define_method(:"#{attribute.name}=") do |value| @_old_targets << _target @_target = _target.with(attribute.name => value) value end end end end |