Created
March 26, 2017 22:08
-
-
Save willmurphyscode/8e1f38e1f693d999d13c3592d9c25efa to your computer and use it in GitHub Desktop.
Demonstration that mutating an array in Ruby changes it's hash value
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
def does_it_change | |
mutable_array = [1,2] | |
hash = {} | |
hash[mutable_array] = 'foo' | |
puts hash[mutable_array].inspect # prints "foo" | |
mutable_array[1] = 3 | |
puts hash[mutable_array].inspect # prints "nil" | |
end | |
does_it_change |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment