Skip to content

Instantly share code, notes, and snippets.

@ancorcruz
Created March 5, 2012 15:15
Show Gist options
  • Save ancorcruz/1978697 to your computer and use it in GitHub Desktop.
Save ancorcruz/1978697 to your computer and use it in GitHub Desktop.
Ruby hash bug
1.9.3p0 :001 > h = Hash.new([])
=> {}
1.9.3p0 :002 > h[:a] << 1
=> [1]
1.9.3p0 :003 > h
=> {}
1.9.3p0 :004 > h[:a]
=> [1]
1.9.3p0 :005 > h[:b] = [2]
=> [2]
1.9.3p0 :006 > h
=> {:b=>[2]}
1.9.3p0 :007 > h[:a]
=> [1]
1.9.3p0 :008 > h[:c] ||= [5]
=> [1]
1.9.3p0 :009 > h
=> {:b=>[2]}
1.9.3p0 :010 > h[:c]
=> [1]
1.9.3p0 :011 > h[:a]
=> [1]
1.9.3p0 :012 > h[:b]
=> [2]
1.9.3p0 :013 >
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment