Skip to content

Instantly share code, notes, and snippets.

@willmurphyscode
Created March 26, 2017 22:08
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 willmurphyscode/8e1f38e1f693d999d13c3592d9c25efa to your computer and use it in GitHub Desktop.
Save willmurphyscode/8e1f38e1f693d999d13c3592d9c25efa to your computer and use it in GitHub Desktop.
Demonstration that mutating an array in Ruby changes it's hash value
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