From: Dave Thomas Date: 2003-08-02T09:38:45+09:00 Subject: Re: RDoc now does constants Hal E. Fulton wrote: > Well, call me crazy, but I sometimes create a Struct > and later (usually as an afterthought) add methods > to it. Me too - but Structs and classes are different enough to make that dangerous at times, so I try not to do it too often. > Personally, I see nothing wrong with this. Some, though, > will perhaps say I should refactor and make my Structs > into "real" classes. Something that can bite you when you do this is: S = Struct.new(:a) class S def getA @a end end s = S.new(123) p s.getA #=> nil Because of this inconsistency, I now subclass Structs a lot less than I used to. Now what I'm experimenting with is something like this: class A construct_with :a, :b def other_method @a += @b ... end end This is a simple code generator which works inside a real class, giving me the best of both worlds. It generates a default #initialize method that sets the instance variables (in this case @a and @b) and generates accessor methods for each. Cheers Dave