Corey
11/11/2004 7:17:00 PM
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.
<snip>
> 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