From: gregarican Date: 2006-03-15T05:58:45+09:00 Subject: Re: Understanding Variable Naming in Ruby Here is a nonsensical class that uses class, instance, and local variables. I don't think creating my own class variable accessors is Rubyish, but I just threw it in there for kicks. class Foo attr_accessor :instVar, :localVar @@classVar="class variable" localVar="local variable" def initialize super @instVar="instance variable" end def self.classVar return @@classVar end def self.classVar=other @@classVar=other return @@classVar end def localVarCheck begin print "#{self}'s local variable is #{localVar}.\n" rescue NameError => e print "#{self}'s local variable doesn't exist! The specific error is:\n#{e}.\n" end end end print "Foo's classVar is set to #{Foo.classVar}.\n" print "Foo's classVar is now changed to #{Foo.classVar="new class variable"}.\n" foo=Foo.new print "foo's instVar is set to #{foo.instVar}.\n" print "foo's instVar is now changed to #{foo.instVar="new instance variable"}.\n" foo.localVarCheck