由于所有位于对象池中的对象都被上溯到它们的基类型,方法多态使得只有在运行时刻才能真正确定到底哪个对象的方法被执行。
Since all objects in the class pool are upcast to their common base class, the polymorphism of the method leads to that which object method will be executed can only be ascertained at runtime.
毕竟,添加这种多态方法的能力是面向对象语言的关键优势之一。
After all, the ability to add such polymorphic methods is one of the key advantages of an object-oriented language.
Ruby中的多态性被亲切地称为“duck typing”(意思是,如果它走起路来像鸭子,叫起来也像鸭子,那么它一定是鸭子!),这种多态性只是对方法名进行匹配的问题。
Affectionately known as "duck typing" (i.e., if it waddles like a duck and quacks like one, then it must be a duck!), polymorphism in Ruby is just a matter of matching method names.
应用推荐