Skip to content

Instantly share code, notes, and snippets.

@patrobinson
Created February 17, 2023 01:25
Show Gist options
  • Save patrobinson/6e43fef1c5b22327ddfe957939c6ed01 to your computer and use it in GitHub Desktop.
Save patrobinson/6e43fef1c5b22327ddfe957939c6ed01 to your computer and use it in GitHub Desktop.
➜ ops git:(main) ✗ irb
irb(main):001:0> m1 = Hash.new { |h1, k1| h1[k1] = Hash.new { |h2, k2| h2[k2] = 0 } }
=> {}
irb(main):002:0> m2 = {}
=> {}
irb(main):003:0> m1 == m2
=> true
irb(main):004:0> m1[1][2] = 3
=> 3
irb(main):005:0> m2[1][2] = 3
Traceback (most recent call last):
4: from /Users/patrickrobinson/.rbenv/versions/2.7.7/bin/irb:23:in `<main>'
3: from /Users/patrickrobinson/.rbenv/versions/2.7.7/bin/irb:23:in `load'
2: from /Users/patrickrobinson/.rbenv/versions/2.7.7/lib/ruby/gems/2.7.0/gems/irb-1.2.6/exe/irb:11:in `<top (required)>'
1: from (irb):5
NoMethodError (undefined method `[]=' for nil:NilClass)
irb(main):006:0>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment