From: Brian Candler Date: 2003-06-01T15:57:23+09:00 Subject: Re: [RCR] attr_reader :foo? On Sun, Jun 01, 2003 at 08:04:16AM +0900, Joel VanderWerf wrote: > Consider the following code: > > class C > attr_accessor :foo? > def initialize > @foo = true > end > end > > c = C.new > p c.foo? # ==> false > c.send("foo?=", true) > p c.foo? # ==> true > p c.instance_variables # ["@foo"] > > You can call the reader. You have to bend over backwards to call the > writer. You cannot access the attribute itself from within method > definitions. You can't even see that it exists using #instance_variables. instance_variables works for me: I get ["@foo?", "@foo"] (version 1.6.8, FreeBSD) But I agree such an instance variable is not directly accessible (e.g. @foo?.inspect fails with a parse error) I guess the ? is being treated as part of the ? : operator rather than the variable name: @foo?.1:.2 # return .1 if @foo is true or .2 if @foo is false Regards, Brian.