方法重载可以通过声明两个具有相同名称和不同签名的方法来实现.这些不同的签名可以是,
method(int a, int b) vs method(String a, String b)
method(a) vs method(a, b)
我们无法使用第一种方法实现方法重载,因为ruby(dynamic typed language)中没有数据类型声明.因此,定义上述方法的唯一方法是def(a,b)
使用第二个选项,看起来我们可以实现方法重载,但我们不能.假设我有两个参数数量不同的方法,
def method(a); end;
def method(a, b = true); end; # 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.
所以ruby需要在方法查找链中维护一个具有唯一名称的方法.