Ahh. So we're not talking about the toplevel. Thanks.

Hal

----- Original Message ----- 
From: Dave Thomas <Dave / thomases.com>
To: ruby-talk ML <ruby-talk / netlab.co.jp>
Sent: Tuesday, October 10, 2000 10:16 PM
Subject: [ruby-talk:5412] Re: Object.foo, setters and so on


> "Hal E. Fulton" <hal9000 / hypermetrics.com> writes:
> 
> > What does this entry in the FAQ mean?
> 
> say you have
> 
>    class Dave
> 
>      def fred
>        @fred
>      end
> 
>      def fred=(n)
>        @fred = n
>      end
> 
>      def test
>        fred = 99
>      end
>    end
> 
> You might be tempted to think that the line 'fred = 99' in method
> 'test' calls the method 'fred='. After all, method calls in functional 
> form have 'self.' implicitly prepended, right?
> 
> Unfortunately not. In this case, Ruby will look at 'fred = 99' and
> simply assign 99 to a local variable 'fred'. To invoke the setter
> method, you need to make the self. explicit:
> 
> 
>      def test
>        self.fred = 99
>      end
> 
> 
> Regards
> 
> 
> Dave
>