From: Brian Candler Date: 2012-09-01T16:24:51+09:00 Subject: Re: Constructor or a Method Rubyist Rohit wrote in post #1074150: > def name(=str) I think you mean def name=(str) > (2) In case I ignore '=' in second method, will it work? Why '=' is > necessary? It's part of the method name. obj.name = 123 # syntactic sugar, calls the name= method obj.name=(123) # same obj.send(:name=,123) # same Note that in the first two cases, the value of the expression is forced to be the value of the argument (not the return value from the method). >> class Foo; def name=(x); @name=x; return 999; end; end => nil >> obj = Foo.new => # >> obj.name = 123 => 123 >> obj.name=(456) => 456 >> obj.send(:name=,789) => 999 >> obj => # >> This is to avoid surprises when chaining together expressions which look like 'assignment'. -- Posted via http://www.ruby-forum.com/.