From: "David A. Black" Date: 2007-12-01T05:55:39+09:00 Subject: Re: Class method Hi -- On Sat, 1 Dec 2007, Todd Benson wrote: > On Nov 30, 2007 12:54 PM, Nathan Viswa 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 -- Upcoming training by David A. Black/Ruby Power and Light, LLC: * Intro to Rails, London, UK, December 3-6 (by Skills Matter) See http://www.rubypal.com for details and 2008 announcements!