From: Dave Thomas Date: 2004-11-12T05:28:45+09:00 Subject: Re: ruby idiom for attribute definition? On Nov 11, 2004, at 14:21, jim@freeze.org wrote: > 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. I'd argue that using the IVs of a parent class is probably not the best thing to do anyway. It couples implementations, not just interfaces. So generally I'll use the attributes of superclasses, not IVs. In that case, the Struct thing is a wash. Cheers Dave