From: Corey Date: 2004-11-12T04:16:48+09:00 Subject: Re: ruby idiom for attribute definition? On Wednesday 10 November 2004 09:40 pm, Dave Thomas wrote: > 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. > class Thing < Struct.new(...) > I can see the usefullness in this, thanks for the heads-up - but I can see that if I had a lot of attributes, it would seem somewhat awkward: class Thing < Struct.new (:attr1, :attr2, :attr3, :attr4, :attr5, :attr6,:attr7, :attr8, :attr9, :attr10 ) # do stuff end Besides, I just get a weird feeling that this Struct approac is kinda odd - to tricky or something - as I'm learning ruby, I'm trying to stick with the most common idioms and oop practices. I guess it's just a matter of personal aesthetics? : class Thing attr_accessor :attr1, :attr2, :attr3, :attr4, :attr5, :attr6,:attr7, :attr8, :attr9, :attr10 # do stuff end Thanks, Corey -- "Good judgment comes from experience. Experience comes from bad judgment." - Jim Horning