On Nov 30, 2007 2:55 PM, David A. Black <dblack / rubypal.com> wrote:
> Hi --
>
> On Sat, 1 Dec 2007, Todd Benson wrote:
>
> > On Nov 30, 2007 12:54 PM, Nathan Viswa <nathanv / rogers.com> wrote:
> >> Need help to understand how the marked <<< def works. Thanks
> >>
> >> class Person
> >>   def initialize(lname, fname)
> >>     @lname = lname
> >>     @fname = fname
> >>   end
> >>
> >>   def lname
> >>     return @lname
> >>   end
> >>
> >>   def fname
> >>     return @fname
> >>   end
> >>
> >>   def lname=(myarg)          # see = <<<
> >>     @lname = myarg
> >>   end
> >
> > You are not defining an equals method here (=).  You are defining the
> > method lname=.  The parser will look for this method before deciding
> > it's an assignment to variable.
>
> It's actually the other way around (if I'm understanding your point
> correctly). If something looks like it *could* be a local variable
> assignment, the parser will assume that it *is* one. Therefore you
> have to use an explicit receiver for methods like lname=, if you want
> to use the syntactic sugar = thing.
>
>
> David

Yeah, after playing around a bit, I see you are right.  It assumes
assignment in the absence of an explicit receiver.  I've never used a
single = in a method name before (aside from the automation provided
by the #attr_ methods of course :)

Todd