Skip to content

Instantly share code, notes, and snippets.

@tyler-smith
Created November 17, 2012 00:54
Show Gist options
  • Save tyler-smith/4092298 to your computer and use it in GitHub Desktop.
Save tyler-smith/4092298 to your computer and use it in GitHub Desktop.
1.9.3p286 :001 > a = Hash.new([])
=> {}
1.9.3p286 :002 > a[:foo] << 1
=> [1]
1.9.3p286 :003 > a[:bar] << 1
=> [1, 1]
1.9.3p286 :004 > b = Hash.new(){[]}
=> {}
1.9.3p286 :005 > b[:foo] << 1
=> [1]
1.9.3p286 :006 > b[:bar] << 1
=> [1]
1.9.3p286 :007 > b[:bar] << 1
=> [1]
1.9.3p286 :009 > b[:bar]
=> []
1.9.3p286 :011 > c = Hash.new(){|h,v|h[v] = []}
=> {}
1.9.3p286 :012 > c[:foo] << 1
=> [1]
1.9.3p286 :013 > c[:bar] << 1
=> [1]
1.9.3p286 :014 > c[:bar] << 2
=> [1, 2]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment