Skip to content

Instantly share code, notes, and snippets.

@gaqzi
Created April 22, 2010 09:06
Show Gist options
  • Save gaqzi/375005 to your computer and use it in GitHub Desktop.
Save gaqzi/375005 to your computer and use it in GitHub Desktop.
# ruby 1.8.7
# Hash implicitly creates an array for empty nodes
a = Hash.new([])
a[:key] << 2 # => [2]
p a # => {} nil
p a[:key] # => [2]
# Explicitly add an array for all nodes before creating
b = Hash.new
b[:key] ||= []
b[:key] << 2 # => [2]
p b # => {:key=>[2]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment