Skip to content

Instantly share code, notes, and snippets.

@marshall-lee
Created October 28, 2015 16:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marshall-lee/2931433af0d4e70f1c2e to your computer and use it in GitHub Desktop.
Save marshall-lee/2931433af0d4e70f1c2e to your computer and use it in GitHub Desktop.
k = [1]
h = {}
h[k] = 1
k << 2
h[k] = 2
p h # {[1, 2]=>1, [1, 2]=>2}
k = [1]
h = {k => 1, (k << 2) => 2}
p h # {[1, 2]=>2}
@tenderlove
Copy link

k = [1]
h = {}
h[k] = 1
k << 2
h[k] = 2
h.rehash # a hash key was mutated

p h # {[1, 2]=>2}

k = [1]
h = {k => 1, (k << 2) => 2} # hash buckets are calculated *after* the mutation

p h # {[1, 2]=>2}

@marshall-lee
Copy link
Author

@tenderlove thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment