From: Iain Barnett Date: 2011-03-25T14:33:55+09:00 Subject: Re: shortcut for add unless nil ? On 24 Mar 2011, at 22:45, Ryan Davis wrote: > The most idiomatic (and performant) shortcut is to not have the situation arise in the first place. Nil checks everywhere is generally a design smell. Push things up to whereever the defaults should be figured out... in railsy parlance: > > thingies = params[:thingies] || [] > > then later you never have to worry about it. > I agree to an extent, but even when you're defining defaults it would be nice: thingies = params[:thingies] || [] wotsits = params[: wotsits] || [] stuff = thingies + wotsits isn't as nice as stuff = params[:thingies] +? params[:wotsits] where +? is my new infix operator of choice for "add unless nil" :) Sometimes I don't want the extra typing or to use extra locals that will only be used for that one line. Iain