Thursday, February 16, 2012

No Method Overloading in Ruby

In Ruby there is no concept of method overloading. One method can have different names but two different method cannot have same names even if the number of arguments are same.

The second method overrides the first and hence there is no existence of the first method with arguments.

In fact, there is no need of method overloading in Ruby. Apparently, method overloading is required for two reasons.
First, methods with same name and accepting different number of arguments.
Second, methods with same name and accepting same number of arguments but different data types.

Both of the above two requirements can be achieved in Ruby.
First, as Ruby method arguments can be declared with default values and hence these arguments can be omitted on method invocation.
Second, as Ruby methods can accept arguments of any class.

No comments:

Post a Comment