Method: ChangeSensitiveArray#dup

Defined in:
lib/yodel/models/core/fields/change_sensitive_array.rb

#dupObject

Calling changed! on @record will call dup on this array before any mutating operation has been performed. We need to store the original unedited version in typecast (the ‘was’ value), then return this array since the mutating operation is being performed on it. Since dup returns self, the array being operated on will be stored in @record.changed, and be modified by the op.



86
87
88
89
90
# File 'lib/yodel/models/core/fields/change_sensitive_array.rb', line 86

def dup
  copy = ChangeSensitiveArray.new(@record.dup, @field.dup, @array.dup)
  @record.typecast[@field] = copy
  self
end