Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Many values can be a string, object, or list #1

Open
jpstroop opened this issue Nov 6, 2014 · 0 comments
Open

Many values can be a string, object, or list #1

jpstroop opened this issue Nov 6, 2014 · 0 comments
Labels

Comments

@jpstroop
Copy link

jpstroop commented Nov 6, 2014

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant