From: Eleanor McHugh Date: 2009-04-03T09:23:50+09:00 Subject: Re: Nilling for GC On 3 Apr 2009, at 00:13, David Masover wrote: > On Thursday 02 April 2009 16:46:37 Eleanor McHugh wrote: > >> hs.delete_if { |k, v| (v.map! { |worker| thread_dead?(worker) ? >> (cleaned += 1; nil) : worker }.compact! || v).empty? } >> >> It always bugs me that compact! returns nil if no changes occur, >> rather than the enum as I seem to use this particular idiom a lot >> *sigh* > > It could also be written like this, if I understand it: > > hs.delete_if { |k, v| (v.map! { |worker| thread_dead?(worker) ? > (cleaned += 1; > nil) : worker }.tap(&:compact!).empty? } > > I don't feel strongly about compact! -- after all, it may be useful > to know > whether it found anything. But this is exactly what tap is for, right? I've only just started moving over to 1.9 so I've not used tap(), I'll bear it in mind for the future. To be honest though I can't recall a single occasion where I've used compact!() that I didn't find the nil result inconvenient and have even been known to redefine it to work the way I prefer when it's been frequently used in a program :) Ellie Eleanor McHugh Games With Brains http://slides.games-with-brains.net ---- raise ArgumentError unless @reality.responds_to? :reason