Skip to content

Instantly share code, notes, and snippets.

@jakeboxer
Last active December 24, 2015 12:49
Show Gist options
  • Save jakeboxer/6800605 to your computer and use it in GitHub Desktop.
Save jakeboxer/6800605 to your computer and use it in GitHub Desktop.
hash = {:dog => 'woof', :cat => 'meow'}
without_dup = hash
with_dup = hash.dup
# BEFORE CHANGE
puts "hash: #{hash.inspect}"
puts "without_dup: #{without_dup.inspect}"
puts "with_dup: #{with_dup.inspect}"
# => hash: {:dog=>"woof", :cat=>"meow"}
# => without_dup: {:dog=>"woof", :cat=>"meow"}
# => with_dup: {:dog=>"woof", :cat=>"meow"}
hash[:cat] = 'hiss'
# AFTER CHANGE
puts "hash: #{hash.inspect}"
puts "without_dup: #{without_dup.inspect}"
puts "with_dup: #{with_dup.inspect}"
# => hash: {:dog=>"woof", :cat=>"hiss"}
# => without_dup: {:dog=>"woof", :cat=>"hiss"}
# => with_dup: {:dog=>"woof", :cat=>"meow"}
hash[:dog].upcase!
# AFTER UPCASE!
puts "hash: #{hash.inspect}"
puts "without_dup: #{without_dup.inspect}"
puts "with_dup: #{with_dup.inspect}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment