From: Adam Prescott Date: 2011-10-05T00:11:22+09:00 Subject: Re: Operator Overloading --00151747bb4cd8cbbd04ae7a8098 Content-Type: text/plain; charset=UTF-8 On Tue, Oct 4, 2011 at 3:53 PM, Darryl L. Pierce wrote: > > (Of course, 'x' and 'self.x' are the same; you can write 'self.x' if you > > think it's clearer) > > I don't think so. 'x' is a local variable, while '@x' is an instance > variable. And since the fields are instance variables they have to be > prefixed with '@'. > Not quite. :) class Foo attr_reader :x def initialize(x) @x = x end def bar x # :) end end f = Foo.new(1) puts f.bar http://ideone.com/mbPc0 If there's no local variable in the scope, the interpreter sees it as a method call. If it's ambiguous, it'll pick the variable over the method call, unless you force it with a trailing (). x = 1 def x; 2; end puts x puts x() --00151747bb4cd8cbbd04ae7a8098--