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

Add an option to parse hash keys as symbols instead of strings #59

Open
joallard opened this issue Apr 8, 2012 · 2 comments
Open

Add an option to parse hash keys as symbols instead of strings #59

joallard opened this issue Apr 8, 2012 · 2 comments

Comments

@joallard
Copy link

joallard commented Apr 8, 2012

This is a feature request. I like symbols. An argument could be made about object duplication and so on, but I just like them because they are easier to type. It would be nice to have an option to parse hash keys as symbols.

For example:

irb(main):001:0> Psych.load("---\n ananas: sweet\n bananas: yellow")
=> {"ananas"=>"sweet", "bananas"=>"yellow"}
irb(main):002:0> Psych.load("---\n ananas: sweet\n bananas: yellow", :symbolize_keys => true)
=> {:ananas=>"sweet", :bananas=>"yellow"}
@kendagriff
Copy link

You could always use HashWithIndifferentAccess from the ActiveSupport library, by calling with_indifferent_access:

require 'active_support/core_ext/hash'
Psych.load("---\n ananas: sweet\n bananas: yellow").with_indifferent_access

@t3hk0d3
Copy link

t3hk0d3 commented May 25, 2013

@kendagriff
It won't automagically convert folded hashes into HashWithIndifferentAccess

foo:
   bar:
      hello:
         world: "yeah"

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

No branches or pull requests

3 participants