From: dblack@... Date: 2002-10-15T06:51:31+09:00 Subject: Re: Referring to instance vars in a Struct? Hi -- On Tue, 15 Oct 2002, Chris Morris wrote: > But the point for me is still the surprise of not having an instance var > inside a Struct (although it does make sense that this is probably pushing > Structs beyond their intended use). One way to look at it: having methods that set and retrieve same-named instance variables is one way of implementing object attributes, and while it's convenient (especially with the attr_xxx wrappers for method creation), it's not the only way. So Structs are in the attribute business, but how they do it is not part of the deal. Of course, if you want to, you can always get under the hood: (s = (S = Struct.new :thing) .new) .thing = 123 # (I was shooting for a palindrome :-) Anyway.... class S alias :oldthing :thing def thing puts "Intercepted attribute get" oldthing end end p s.thing # => Intercepted attribute get # 123 etc. David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav