From: Thufir Date: 2008-02-22T21:33:22+09:00 Subject: Re: ||= [] idiom On Wed, 20 Feb 2008 07:21:15 +0900, MenTaLguY wrote: > I sometimes do this sort of thing: > > ( @categories[resource.tag] ||= [] ) << resource > > Although this might possibly be more readable: > > category = ( @categories[resource.tag] ||= [] ) category << resource > > Often it can make sense to factor the ||= portion into a separate > method: > > def category_for(tag) > @categories[tag] ||= [] > end > > # ... > > category_for(resource.tag) << resource > > -mental > What's the real-world application of this? thanks, Thufir