From: Jay Levitt Date: 2007-08-29T11:25:08+09:00 Subject: Re: idiomatic way to assign if not nil? On Aug 28, 8:00 pm, dbl...@wobblini.net wrote: > >> On 29 Aug 2007, at 00:30, Jay Levitt wrote: > > >>> a = b if b > > >>> Does that exist in a DRYer form? > > I have to say, when I type this: > > a = b if b > > I don't have the feeling that I'm repeating myself; the two b's both > pull their weight. So I wouldn't worry about it, from the DRY > perspective. Yeah, it was more that I was doing a bunch of them at once to deal with Rails' attr_protected feature while in a unit test, so I ended up writing: user.login = options[:login] if options[:login] user.password = options[:password] if options[:password] user.other = options[:other] if options[:other] Felt kinda repetitive. I guess I could DRY that up in an eval loop.