From: dblack@... Date: 2003-05-09T08:11:43+09:00 Subject: Re: Can a global be a constant? Hi -- On Fri, 9 May 2003, Hal E. Fulton wrote: > ----- Original Message ----- > From: "Brian Candler" > To: "ruby-talk ML" > Sent: Thursday, May 08, 2003 5:44 PM > Subject: Re: Can a global be a constant? > > > > On Fri, May 09, 2003 at 07:04:40AM +0900, Jim Freeze wrote: > > > Ok. I didn't realize that $, @, and @@ were considered part > > > of the name. Makes sense now. > > > > And you'll see this if you try to access one of these things using the > > symbol: > > > > class Foo; end > > a = Foo.new > > a.instance_variable_set(:@bar,1) #>> OK > > a.instance_variable_set(:bar,1) #>> NameError: 'bar' is not an > > instance variable name > > Yet this is potentially confusing, because a > line like attr_accessor :foo does create an > accessor for @foo. > > I suppose the rationale is that you're specifying > the symbol corresponding to the method name rather > than the instance variable. There are lots of fun things you can do with names when you start setting them manually: $ cat weird.rb class << o=Object.new define_method("&!#?") { puts "Weird method name!" } end o.send("&!#?") $ ruby weird.rb Weird method name! :-) David -- David Alan Black home: dblack@superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav