From: Brian Candler Date: 2011-01-27T07:32:48+09:00 Subject: Re: ruby treatment of method defs James Byrne wrote in post #977707: > I presume that there exists a strong reason why this construct remains > in the language. However, I have not been able to find an explanation > as to why this behaviour is desired so if someone here could inform me > as to why it is retained then I would be much obliged. Here is one recent explanation: http://www.ruby-forum.com/topic/941686#977592 g = 123 is an assignment to a local variable. (Local variables are not objects; they are slots on the stack frame, which hold references to objects) foo.g = 123 is syntactic sugar for a method call. The method's name is "g=" and the argument is 123. It's the same as foo.send(:g=, 123) A bareword "g", such as in "puts g", could be either a local variable or a method call. The choice is made at parse time, which is before run time. What this gives you is uncluttered syntax with efficiency. There's no need to declare g as a variable, nor do you need to use parentheses to call function f(). But because the distinction is made ahead-of-time, it doesn't have to be decided every time the code is executed in a loop. -- Posted via http://www.ruby-forum.com/.