Need some help understanding this method - Assignment in method def
Posted 26 April 2012 - 03:01 PM
I'm currently going through Michael's Hartl Rails tutorial and I ran across this which I can not understand and would like some input from the bright minds here as to what is really going on. I have never seen an assignment in a method def. The tutorial doesn't elaborate enough for me to understand. Thanks in advance.
@current_user = user
This post has been edited by rvbsanjose: 26 April 2012 - 03:02 PM
Re: Need some help understanding this method - Assignment in method def
Posted 27 April 2012 - 01:57 AM
The line def current_user=(user) defines a method named "current_user=" with a parameter called "user". In ruby a method's name may contain a "=" as its last character. Such methods may be called using the syntax object.foo = bar. So when you see a statement of that form, it will call the method foo= with the argument bar on the object object, which is to say that a statement of the form foo.bar = baz is always a method call.