Module: Toy::Cloneable

Extended by:
ActiveSupport::Concern
Included in:
Dirty, Object
Defined in:
lib/toy/cloneable.rb

Instance Method Summary collapse

Instance Method Details

#initialize_copy(other) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/toy/cloneable.rb', line 5

def initialize_copy(other)
  instance_variables.each do |name|
    instance_variable_set(name, nil)
  end

  @attributes  = {}

  other.attributes.except('id').each do |key, value|
    value = value.duplicable? ? value.clone : value
    send("#{key}=", value)
  end
end