From: Robert Klemme Date: 2004-07-29T18:56:44+09:00 Subject: Re: Automatically setting attributes "Laughlin, Joseph V" schrieb im Newsbeitrag news:67B3A7DA6591BE439001F27362333512030B09CA@xch-nw-28.nw.nos.boeing.com... > How can I do something like the following: > > class Foo > > attr_accessor :goo, :moo > > def initalize > @attr.each { | attrib| attrib = 0 } > end > end > > In case it's not clear, I want to set all attributes of the Foo object > to zero. But I can't seem to get the syntax for it correct. How about: class Foo attr_accessor :goo, :moo def initialize(h={}) h.each {|k,v| send("#{k}=", v)} end end foo = Foo.new(:goo => 10, :moo => 20) Regards robert