From: Rick DeNatale Date: 2009-08-28T23:06:59+09:00 Subject: Re: Mass Assignment on Clas On Fri, Aug 28, 2009 at 7:03 AM, Pete Moran wrote: > I am a total newbie to Ruby, so please bare with me. Averting my eyes, I'd prefer to keep my clothes on myself! In other words I'll grin and BEAR it! Seriously, David Black already gave you pretty much the response I would have, although my first steps in refining it a bit might be to make the hash arg optional: def initialize(items={} items.each do |key,value| instance_variable_set("@#{key}", value) end end Another thing variation would be to use those accessors so as to not add 'accidental' instance variables def initialize(items={} items.each do |key,value| send("#{key}=", value) rescue raise "unknown attribute #{key}" end end And as the King of Siam said, etcetera, etcetera, etcetera! -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale