Skip to content

Instantly share code, notes, and snippets.

@netshade
Last active June 29, 2016 14:22
Show Gist options
  • Save netshade/b7e6be552d7257d274f5988b857ecdcc to your computer and use it in GitHub Desktop.
Save netshade/b7e6be552d7257d274f5988b857ecdcc to your computer and use it in GitHub Desktop.
wtf
irb(main):001:0> h = Hash.new(Hash.new(0))
=> {}
irb(main):002:0> h[:foo][:bar] += 1
=> 1
irb(main):003:0> h
=> {}
irb(main):004:0> h.empty?
=> true
irb(main):005:0> h[:foo]
=> {:bar=>1}
irb(main):006:0> h.each { |k, v| puts [k, v].inspect }
=> {}
irb(main):007:0> RUBY_VERSION
=> "2.2.2"
irb(main):012:0> RUBY_PLATFORM
=> "x86_64-darwin14"
@netshade
Copy link
Author

Ah,

irb(main):013:0> h = Hash.new { Hash.new(0) }
=> {}
irb(main):014:0> h[:foo][:bar] += 1
=> 1
irb(main):015:0> h
=> {}
irb(main):016:0> h[:foo]
=> {}

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