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

Nested Hash / Default value is not stored #208

Closed
antulik opened this issue Aug 22, 2014 · 5 comments
Closed

Nested Hash / Default value is not stored #208

antulik opened this issue Aug 22, 2014 · 5 comments

Comments

@antulik
Copy link

antulik commented Aug 22, 2014

Seems like default value is returned but not stored.

Not sure if it makes sense to have that feature in Hashie, but it would be useful for creation of nested hashes.

> h = Hashie::Mash.new nil, {}
=> {}
> h.a['b'] = 1
=> 1
> h.inspect
=> "#<Hashie::Mash>"
@dblock
Copy link
Member

dblock commented Aug 22, 2014

I think this could be useful, indeed.

@antulik
Copy link
Author

antulik commented Aug 26, 2014

This is a way to get nested hash

> nested_hash = Hash.new { |hash, key| hash[key] = Hash.new(&hash.default_proc) }
=> {}
> nested_hash[:x][:y][:z] = :xyz
=> :xyz
> nested_hash 
=> {:x=>{:y=>{:z=>:xyz}}}

but this does not work for Hashie

h = Hashie::Mash.new { |mash, key| mash[key] = mash.class.new(&mash.default_proc) }
=> {}
> h[:x][:y][:z] = :xyz
=> :xyz
> h
=> {"x"=>{}}

@antulik antulik changed the title Default value is not stored Nested Hash / Default value is not stored Aug 26, 2014
@michaelherold
Copy link
Member

Seems like this might be a duplicate of #60. I agree that it's useful and I think implementing this would also handle the other case!

@brauliobo
Copy link

@michaelherold @dblock the last case reported by @antulik is actually a bug

@dblock
Copy link
Member

dblock commented Aug 17, 2017

@brauliobo Want to take a stab at fixing it? At least write a spec?

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

No branches or pull requests

4 participants