Created
March 21, 2017 13:23
-
-
Save k-hamada/7c1234c1828a52c2f8cb01da71578d55 to your computer and use it in GitHub Desktop.
Hashie shallow copy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👀 ttps://github.com/hashie/hashie/pull/195/