Skip to content

Instantly share code, notes, and snippets.

@k-hamada
Created March 21, 2017 13:23
Show Gist options
  • Save k-hamada/7c1234c1828a52c2f8cb01da71578d55 to your computer and use it in GitHub Desktop.
Save k-hamada/7c1234c1828a52c2f8cb01da71578d55 to your computer and use it in GitHub Desktop.
Hashie shallow copy
[1] pry(main)> class MyHash < Hash
[1] pry(main)* include Hashie::Extensions::MergeInitializer
[1] pry(main)* include Hashie::Extensions::IndifferentAccess
[1] pry(main)* end
=> MyHash
[2] pry(main)> h={a: {b: 1}}
=> {:a=>{:b=>1}}
[3] pry(main)> h
=> {:a=>{:b=>1}}
[4] pry(main)> MyHash.new(h)
=> {"a"=>{"b"=>1}}
[5] pry(main)> h
=> {:a=>{"b"=>1}}
[6] pry(main)> h={a: {b: 1}}
=> {:a=>{:b=>1}}
[7] pry(main)> MyHash.new(h.deep_dup)
=> {"a"=>{"b"=>1}}
[8] pry(main)> h
=> {:a=>{:b=>1}}
@k-hamada
Copy link
Author

👀 ttps://github.com/hashie/hashie/pull/195/

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