Class: Perpetuity::Duplicator
- Inherits:
-
Object
- Object
- Perpetuity::Duplicator
- Defined in:
- lib/perpetuity/duplicator.rb
Instance Attribute Summary collapse
-
#object ⇒ Object
readonly
Returns the value of attribute object.
Instance Method Summary collapse
- #attribute(ivar) ⇒ Object
- #duplicate_attribute(ivar) ⇒ Object
-
#initialize(object) ⇒ Duplicator
constructor
A new instance of Duplicator.
- #set_attribute(ivar, value) ⇒ Object
Constructor Details
#initialize(object) ⇒ Duplicator
Returns a new instance of Duplicator.
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/perpetuity/duplicator.rb', line 4 def initialize object if object.is_a? Array @object = object.map { |i| Duplicator.new(i).object } else @object = object.dup rescue object end @object.instance_variables.each do |ivar| duplicate_attribute ivar end end |
Instance Attribute Details
#object ⇒ Object (readonly)
Returns the value of attribute object.
3 4 5 |
# File 'lib/perpetuity/duplicator.rb', line 3 def object @object end |
Instance Method Details
#attribute(ivar) ⇒ Object
15 16 17 |
# File 'lib/perpetuity/duplicator.rb', line 15 def attribute ivar object.instance_variable_get ivar end |
#duplicate_attribute(ivar) ⇒ Object
23 24 25 |
# File 'lib/perpetuity/duplicator.rb', line 23 def duplicate_attribute ivar set_attribute ivar, Duplicator.new(attribute(ivar)).object end |
#set_attribute(ivar, value) ⇒ Object
19 20 21 |
# File 'lib/perpetuity/duplicator.rb', line 19 def set_attribute ivar, value object.instance_variable_set ivar, value end |