From: "David A. Black" Date: 2007-09-22T18:41:49+09:00 Subject: Re: question re: modules and class variable scope Hi -- On Sat, 22 Sep 2007, Gary Wright wrote: > So despite the fact that class variables and instance variables both > use a similar syntactical sigil (@@ vs @), they are scoped in vastly > different ways. I honestly wish that class variables looked like $$this, rather than @@this. They're so completely unrelated to, and radically different from, instance variables, whereas they're much more akin to globals. The @/@@ thing has caused more confusion than anything else in Ruby, I believe. > class variables: resolved at parse time relative to lexical scope > instance variables: resolved at execution time relative to 'self' > > My advice is to just stay away from class variables entirely. Simply use > class instance variables instead. I agree. If you want to maintain state per class, do it the way state is normally maintained per object. David -- Upcoming training from Ruby Power and Light, LLC: * Intro to Ruby on Rails, Edison, NJ, October 23-26 * Advancing with Rails, Edison, NJ, November 6-9 Both taught by David A. Black. See http://www.rubypal.com for more info!