active_attr icon indicating copy to clipboard operation
active_attr copied to clipboard

Typecasting re-typecasts at every method call

Open bramski opened this issue 8 years ago • 0 comments

class MyItemObject
  include ActiveAttr::Model
  attribute :one
  attribute :two
end

Class MyObject
  include ActiveAttr::Model
  attribute :my_objects, type: [MyArrayObject], typecaster: -> { |values| values.map { |value| MyItemObject.new(value) }
end

object = MyObject.from_json(json_dump)
puts object.my_objects.object_id
puts object.my_objects.object_id

This will produce a different object_id at each run. Can't say I expected this. If typecasting results are temporary perhaps they should be returned as frozen?

bramski avatar Apr 11 '17 22:04 bramski