Generally there are two types of methods, ie.
- Functional methods - that returns a value after the method is run or called
- Procedural methods - that changes the internal state of the object
An example of a functional method would be
def max(num, another_num)
num > another_num ? num : another_num
end
which will return maximum number that can be used to perform some other computation.
A simple example of procedural method can be the setters or attribute accessors in ruby, like
class Person
def name=(name)
@name = name
end
end
the above method is changing the internal state of the Person object i.e. by setting the instance variable @name to the value provided.
So it all depends what kind of method you are writing, the intention of your method and how you are going to use it. In other words, if its a procedural method then you can return nil at the end but personally I have never done that yet i.e. returning nil when only changing the state of the object because that will just add a line of code and also make the method look complex without adding any value to the method.
However, Ruby always returns the value of the last evaluated statement from the method whether it is a procedural or a functional method which actually makes it convenient to evaluate the method or some condition inside the method under some circumstances.