On 5/20/06, Robert Klemme <shortcutter / googlemail.com> wrote:
> 2006/5/20, Alder Green <alder.green / gmail.com>:
> > irb(main):001:0> class Bar; def foo=(val); puts "Bar#foo= called!"; end; end
> > irb(main):002:0> Bar.new.instance_eval { foo = 1 }          #=> no output
> > irb(main):003:0> Bar.new.instance_eval { foo= 1 }           #=> no output
> > irb(main):004:0> Bar.new.instance_eval { self.foo = 1 }   #=> Bar#foo= called!
> >
> > It seems like the only way to call Bar#foo= inside and instance of Bar
> > is by prefixing self explicitly. Am I right about this?
>
> Yes.  foo= is a local variable assignment. See
> http://ruby-doc.org/docs/ProgrammingRuby/html/tut_expressions.html#S3
> (you'll have to scroll down a bit).
>
> Kind regards
>
> robert
>
> --
> Have a look: http://www.flickr.com/photos/fussel-foto/
>
>

Yup. Seems like assignments to local variable take foo precedence over
calling foo=. Kind of a shame, since I have to use self.foo= whenever
I want to call foo=. A bit ugly. Which is why I wanted to make sure
there's no alternative.

-- 
-Alder