Good afternoon guys.
I know Ruby accepts three special characters in the method name: '!', '?' and '='. I need to know what the "=" indicates and what it does.
Good afternoon guys.
I know Ruby accepts three special characters in the method name: '!', '?' and '='. I need to know what the "=" indicates and what it does.
The method that contains the special character "=" indicates that that method is a setter.
In Java, we define a setter like this:
public class Welcome{
private int number;
public void setNumber(int number){
this.number = number;
}
}
In Ruby, a setter is defined this way:
class Welcome
def hello=(mymessage)
@message = mymessage
end
end
For more information, see the documentation link on this subject: Ruby doc
Link to the same question in the international forum: What does the ('=') symbol mean when put the method name in a method definition?