Method overloading can be achieved by declaring two methods with the same name and different signatures. These different signatures can be either
1.Arguments with different data types, eg: method(int a, int b) vs method(String a, String b) or
2.Variable number of arguments, eg: method(a) vs method(a, b)
Method overloading cant be achieved with the first option because ruby doesnt have the feature of data type declaration or we can say dynamic typed language. So now the above method can be defined only as def(a,b)
Whereas if we look upon the second option we may feel that we can achieve method overloading through it but we cannot, the reason being if suppose we have two methods with different number of arguments.
def method(a, b = true);
# second argument has a default value method(10)
# Now the method call can match the first one as well as the second one,
# so here is the problem. So the latter method will be called if we call 2
methods with same name.
In object oriented programming, method overriding is a language feature in which a subclass can provide an implementation of a method which is already mentioned by its super classes.
The implementation of a method in the subclass replaces the implementation of a method in the super class.
Here's an example:
puts 'In class A'
class B < A
puts 'In class B'
b = B.new
The method a in class B overrides the method a in class A.