Skip to content

Instantly share code, notes, and snippets.

@rdammkoehler
Last active May 13, 2016 00:49
Show Gist options
  • Select an option

  • Save rdammkoehler/12ca9f092c67652bbd34f859ac1f034a to your computer and use it in GitHub Desktop.

Select an option

Save rdammkoehler/12ca9f092c67652bbd34f859ac1f034a to your computer and use it in GitHub Desktop.
Not what you thought you'd get
a = [ { :items => [{ 'item' => 'junk' },{ 'item' => 'junk' },{ 'item' => 'junk' }] }]
# => [{:items=>[{"item"=>"junk"}, {"item"=>"junk"}, {"item"=>"junk"}]}]
a[0][:items].count # => 3
d = [] # => []
d.push a[0][:items] # => [[{"item"=>"junk"}, {"item"=>"junk"}, {"item"=>"junk"}]]
d.count # => 1, not 3
d.push a[0][:items] # => [[{"item"=>"junk"}, {"item"=>"junk"}, {"item"=>"junk"}], [{"item"=>"junk"}, {"item"=>"junk"}, {"item"=>"junk"}]]
d.count # => 2, not 6
d.flatten.count # => 6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment