# More class variables. Probably shouldn't get into this until you're # happy with the general idea from classvar.rb. This should demonstrate # the way that scoping and so on works with classvars. class A @@foo = "class variable foo" @foo = "class instance variable foo" # Superfluous, but I was learning at this point ;) def self.evaluate(txt) instance_eval txt end def self.eval_block(&block) instance_eval &block end end begin p A.instance_eval { @@foo } rescue => e puts e end @@foo = "hi" p A.instance_eval { [self, @@foo, @foo] } p A.evaluate("[self, @@foo, @foo]") p A.eval_block { [self, @@foo, @foo] } class B @@foo = "B's class variable foo" @foo = "B instance foo" def self.eval_block(&block) instance_eval &block end end p B.eval_block { [self, @@foo, @foo] } class C @@foo = "C's class variable foo" @foo = "C instance foo" def self.eval_block(&block) instance_eval &block end end # N.B. Not C, just B again p B.eval_block { [self, @@foo, @foo] }