From: Dave Thomas Date: 2004-11-11T13:40:43+09:00 Subject: Re: ruby idiom for attribute definition? On Nov 10, 2004, at 22:27, Corey wrote: > ( I've got a really small class going, with about 9 or 10 simple > attributes - > each of them readable and writeable. ) Have you considered using Struct for this? It creates the initialize method for you, as well as all the attribute accessors. You can extend the class it creates, but you have to access the attributes via accessors, and not via instance variables irb(main):001:0> Thing = Struct.new(:name, :age) => Thing irb(main):002:0> class Thing irb(main):003:1> def desc irb(main):004:2> "Person #{self.name} is #{self.age} years old" irb(main):005:2> end irb(main):006:1> end => nil irb(main):007:0> t = Thing.new("Walter", 22) => # irb(main):008:0> t.desc => "Person Walter is 22 years old" You could also say class Thing < Struct.new(...) Cheers Dave