Skip to content

Instantly share code, notes, and snippets.

@Frost
Created July 19, 2012 18:35
Show Gist options
  • Save Frost/3145873 to your computer and use it in GitHub Desktop.
Save Frost/3145873 to your computer and use it in GitHub Desktop.
Ruby Hash wat.
# So, let's create a Hash with an empty Array as the default value...
0|frost tiamat >> irb
irb(main):001:0> h = Hash.new []
=> {}
irb(main):002:0> h[42] << "foo"
=> ["foo"]
irb(main):003:0> h
=> {}
irb(main):004:0> h[42] += ["bar"]
=> ["foo", "bar"]
irb(main):005:0> h
=> {42=>["foo", "bar"]}
irb(main):006:0> h[49]
=> ["foo"]
irb(main):007:0>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment