Let's look at the following code.
In the above case the method returns the sum of two variables.
In Ruby the output of the last line is auto returned. We don't have to use
return
to return the values of the last line.
Let's see the above code without the return
statement.
As you can see the result is same. That's because the last line of the method is auto returned.
Let's see one more example. We had seen following code earlier.
Let's not use return
for the last line and then let's see what the result is.
The final output is the same.
Note that this "auto return" only works only for the very last statement of the method.