Last active
December 24, 2015 12:49
-
-
Save jakeboxer/6800605 to your computer and use it in GitHub Desktop.
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
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