From: Martin DeMello Date: 2012-05-01T06:26:16+09:00 Subject: Re: Question about array of hashes On Mon, Apr 30, 2012 at 1:52 PM, Ralph Shnelvar wrote: > irb(main):001:0> kitty_toys = > irb(main):002:0* [:shape => 'sock', :fabric => 'cashmere'] + > irb(main):003:0* [:shape => 'mouse', :fabric => 'calico'] + > irb(main):004:0* [:shape => 'eggroll', :fabric => 'chenille'] > => [{:shape=>"sock", :fabric=>"cashmere"}, {:shape=>"mouse", :fabric=>"calico"}, {:shape=>"eggroll", :fabric=>"chenille"}] > irb(main):024:0> kitty_toys.size > => 3 > > Why is the kitty_toys syntax even legal? If a series of key:value pairs are the last elements in an argument list, they get collected into a single hash. It's basically the method call hash argument collection, being applied to the [] method here. See http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_methods.html martin