From: Christopher Swasey Date: 2008-02-20T07:29:50+09:00 Subject: Re: ||= [] idiom ------=_Part_14352_1589857.1203460192038 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On 2/19/08, Leslie Viljoen wrote: > > I often make use of this idiom to add something to an array in a hash of > arrays: > > @categories = {} > > pagelist.each do |resource| > @categories[resource.tag] ||= [] > @categories[resource.tag] << resource > end > > > .. is there a better way? Can the two @categories lines > be made into one? @categories = {} pagelist.each do |resource| (@catetegories[resource.tag] ||= []) << resource end Christopher ------=_Part_14352_1589857.1203460192038--