Skip to content

Instantly share code, notes, and snippets.

@eevee
Last active August 29, 2015 14:06
Show Gist options
  • Save eevee/4dcfe41ae4b1d906adee to your computer and use it in GitHub Desktop.
Save eevee/4dcfe41ae4b1d906adee to your computer and use it in GitHub Desktop.
mutable hash keys in ruby
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