From: Dave Thomas Date: 2004-11-12T04:06:39+09:00 Subject: Re: ruby idiom for attribute definition? On Nov 11, 2004, at 12:52, jim@freeze.org wrote: > * Dave Thomas [2004-11-11 13:40:43 +0900]: > >> You could also say >> >> class Thing < Struct.new(...) >> > > This got me thinking, so I tried the following: > > class A < Struct.new(:a) > def peek > puts @a > end > end > > A.new.peek > > Turns out that this does not work since @a is NOT defined. > Problem is, I can't see any instance variables defined > inside a struct. Where does it keep the data? That's why I said you have to use the accessor methods. Structs cheat. Matz: we discussed this before, but it would be really nice if Struct set up the IVs too: that way this idiom would be more generally useful. Cheers Dave