From: Jay Levitt Date: 2007-08-29T14:35:07+09:00 Subject: Re: idiomatic way to assign if not nil? On Aug 28, 10:31 pm, "Logan Capaldo" wrote: > On 8/28/07, Jay Levitt wrote: > > 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. > > Is this not what #attributes= is for? > user.attributes = options Nope! That won't assign any attributes that are attr_protected.