From: jim@... Date: 2004-11-12T05:21:18+09:00 Subject: Re: ruby idiom for attribute definition? * Dave Thomas [2004-11-12 04:46:04 +0900]: > Exactly - that's what made me suggest it. A class with a large number > of attr_accessors is not really an encapsulated class, so it felt to me > that a Struct would be more appropriate. Below is an example that speaks to your comment about structs not being generally useful for inheritance: S = Struct.new(:a, :b) class C < S attr_accessor :c, :d def do_something_clever "#{a} : #{b} | #{@c} : #{@d}" end end The problem is that I have to know which IV came from C and which came from Struct. I suppose that I could use the getter/setter methods for all IV's, but I thought that @c was avoiding a function call that 'c' was making, and I would like to avoid that. Dave, earlier you suggested that Structs cheat. Well, I suppose I could try to out cheat the struct with: class C < S attr_accessor :a, :b, :c, :d def ... end end Now I get all the benefits of Struct for :a and :b, but the problem is that I am violating DRY. -- Jim Freeze