You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
See 5.3. Should we try to handle this gracefully, e.g. to avoid:
irb(main):005:0> f='foo'=>"foo"irb(main):006:0> f << 'x'=>"foox"
? We could assume everything is an Array and then change to a single String or Object when we serialize if there's is only one member.
But what are the implications for marshaling/unmarshaling?
Every value that isn't an array would need to become one when we unmarshal (parse)
Accessors and mutators would need to initialize lists internally, so ruby def foo=(value) data['foo'] ||= [] data['foo'] << value end def foo data['foo'] ||= [] data['foo'] end
And []= and [] would need to be overridden with the same behavior.
This feels like it breaks Ruby. If I say x = 1 I want x == 1, not [1], and I want << to behave as expected based on the type I'm working against. Better you just know your data.
The text was updated successfully, but these errors were encountered:
See 5.3. Should we try to handle this gracefully, e.g. to avoid:
? We could assume everything is an Array and then change to a single String or Object when we serialize if there's is only one member.
ruby def foo=(value) data['foo'] ||= [] data['foo'] << value end def foo data['foo'] ||= [] data['foo'] end
And
[]=
and[]
would need to be overridden with the same behavior.This feels like it breaks Ruby. If I say
x = 1
I wantx == 1
, not[1]
, and I want<<
to behave as expected based on the type I'm working against. Better you just know your data.The text was updated successfully, but these errors were encountered: