From: Robert Klemme Date: 2008-02-21T01:44:33+09:00 Subject: Re: ||= [] idiom 2008/2/20, Leslie Viljoen : > On Feb 20, 2008 11:44 AM, Robert Klemme wrote: > > But it needs the fix Joel pointed out: > > > > @categories = Hash.new {|h,k| h[k] = []} > > > > Theoretically this could even be more efficient than > > > > (@categories[k] ||= []) << v > > > > because the check is done only once per missing key. > > A benchmark does indeed show it to be faster, though you need truly huge arrays > to see the difference. As long as it's not slower for small number of values per key... :-) Thanks for letting us know! Cheers robert -- use.inject do |as, often| as.you_can - without end