From: Brian Candler Date: 2012-11-28T03:25:25+09:00 Subject: Re: Novice: Understanding instance 'variables' and methods Steve Tu wrote in post #1086651: > The original code just had the method 'test' which in effect was a > setter (presumably in Ruby parlance it could have been better called > test= ?). Kind-of. There is special syntactic sugar for methods with names like test=. foo.test = 123 is mapped to a method call of the "test=" method, even though this looks like an assignment (and there may be spaes around the equals sign). It's the same as: foo.send(:test=, 123) Furthermore, the return value of the method is forced to be 123, even if it explicitly returns something else. There are other examples: def [](k) ... end foo[123] def[]=(k,v) ... end foo[123] = 456 And even operators like + and - map to methods class Test # binary + def +(other) ... end # unary + def +@ ... end end -- Posted via http://www.ruby-forum.com/.