Skip to content

Instantly share code, notes, and snippets.

@bartlomiejdanek
Created April 9, 2013 05:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bartlomiejdanek/5343293 to your computer and use it in GitHub Desktop.
Save bartlomiejdanek/5343293 to your computer and use it in GitHub Desktop.
hash clone/dup/deep_dup fail
require 'active_support/core_ext/hash/deep_dup'
h = {a: {b: :c}, d: {e: {f: :g}}}
p "Base h: #{h.object_id}"
p "Base h[:a]: #{h[:a].object_id}"
p "Base h[:d][:e][:f] #{h[:d][:e][:f].object_id}"
puts "--------------------------------------------------------------"
_dup = h.dup
p "Dup h: #{_dup.object_id}"
p "Dup h[:a]: #{_dup[:a].object_id}"
p "Dup h[:d][:e][:f] #{_dup[:d][:e][:f].object_id}"
puts "--------------------------------------------------------------"
_clone = h.clone
p "Clone h: #{_clone.object_id}"
p "Clone h[:a]: #{_clone[:a].object_id}"
p "Clone h[:d][:e][:f] #{_clone[:d][:e][:f].object_id}"
puts "--------------------------------------------------------------"
_deep_dup = h.deep_dup
p "deep_dup h: #{_deep_dup.object_id}"
p "deep_dup h[:a]: #{_deep_dup[:a].object_id}"
p "deep_dup h[:d][:e][:f] #{_deep_dup[:d][:e][:f].object_id}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment