Open ErickFabian opened 2 years ago
@ErickFabian This way we are using defaults kind of weird, Ex.
test = Test.new
test.roles #=> { teacher: {}, student: {}}
test.roles = {}
test.roles #=> { teacher: {}, student: {}}
test.roles = nil
test.roles #=> { teacher: {}, student: {}}
Default values should be only returned when the attributes has never been set. Ex.
test = Test.new
test.roles #=> { teacher: {}, student: {}}
test.roles = {}
test.roles #=> {}
test.roles = nil
test.roles #=> nil
We need some consistency and not unexpected behaviors. We should see how other libraries for class attributes work, like ActiveModel::Attributes, dry-types, etc
@alejandrodevs That was sort of the error, the school_contract property was set to {} but it should always at least have { teacher: {}, students: {} }
the behaviour you are proposing is what is happening now
I'm not exactly sure if this bevahiour change is the right thing to do, i wanted to get feedback on it too, i'm not super set on if this should happen or not
Properties set with a non nil value would not be overwritten using the default value