From: Brian Marick Date: 2007-11-16T08:07:51+09:00 Subject: Re: instance variables as class variable ? @x is an instance variable belonging to the object-that-is-a-class, not to an-object-that-is-an-instance-of-that-class. I cover this with some helpful pictures here: Drawing pictures really helps in figuring out what's going on. On Nov 15, 2007, at 2:15 PM, wbsurfver@yahoo.com wrote: > > I'm trying to get a handle on why the following code works by printing > out 'frog' > because @x looks like instance variable syntax. I know that some of > these things don't work the way I'd expect. > > class Test > @x = 'frog' > > class << self > attr_reader :x > end > > end > > puts Test.x ----- Brian Marick, independent consultant Mostly on agile methods with a testing slant www.exampler.com, www.exampler.com/blog, twitter.com/marick ----- Brian Marick, independent consultant Mostly on agile methods with a testing slant www.exampler.com, www.exampler.com/blog, twitter.com/marick