From: dave.burt@... Date: 2005-10-28T11:07:04+09:00 Subject: Re: "Reflecting" on my self.n00b You can save yourself some RSI by using attr_accessor. class ServiceProfile attr_accessor :username, :url, :password, :owner, :certificate def load_certificate() @certificate.read end def call yield self end def each_attribute(&block) (methods - Object.instance_methods).each &block end end class MyService < ServiceProfile attr_accessor :extra end svc_profile = MyService.new svc_profile.each_attribute do |meth| print "Enter #{meth}: " svc_profile.send(meth, gets.chomp) end svc_profile.each_attribute {|meth| puts svc_profile.send(meth) } If you want to use validation, too, you can easily write a method like attr_accessor. See Dwemthy's Array for how. http://poignantguide.net/dwemthy/ A type-checking attr_accessor-ish method might look something like this: def ServiceProfile.typed_attr(hash) attr_reader *hash.keys hash.each_pair do |attr, klass| define_method("#{attr}=") do |value| raise TypeError, "not a #{klass}: #{value.inspect}" unless value.kind_of?(klass) instance_variable_set "@#{attr}", value end end end Cheers, Dave