Last active
August 29, 2015 14:06
-
-
Save eevee/4dcfe41ae4b1d906adee to your computer and use it in GitHub Desktop.
mutable hash keys in ruby
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
irb(main):001:0> h = {} | |
=> {} | |
irb(main):002:0> a = [1, 2, 3] | |
=> [1, 2, 3] | |
irb(main):003:0> h[a] = 5 | |
=> 5 | |
irb(main):004:0> h | |
=> {[1, 2, 3]=>5} | |
irb(main):005:0> h[[1, 2, 3]] | |
=> 5 | |
irb(main):006:0> a[0] = 0 | |
=> 0 | |
irb(main):007:0> a | |
=> [0, 2, 3] | |
irb(main):008:0> h | |
=> {[0, 2, 3]=>5} | |
irb(main):009:0> h[a] | |
=> nil | |
irb(main):010:0> h[[1, 2, 3]] | |
=> nil | |
irb(main):011:0> h[[0, 2, 3]] | |
=> nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment