绝不。Ruby 不支持MI(但将特征视为有用的替代方案)。
无论如何,这个类的重新定义是不明确的,并且会根据特定的 Ruby 实现产生不同的效果。当我运行给定的代码时,我得到“TypeError: superclass mismatch for class ..”(Ruby 1.9.2;在 1.9.3 中,错误出现延迟)。
如果有问题的代码没有导致这样的错误,MyTest.superclass
请检查重新定义后超类的真正含义:注意#superclass
返回单个类对象,而不是集合。
下面是一个反例,认为这种重新定义方案不会添加或指示 MI:
class A
def a; "a"; end
end
class B
def b; "b"; end
end
class C < A
end
# This may raise said TypeError, but if it does not then ..
class C < B
end
# .. either this will work
C.new.a
# .. /or possibly/ this will work
C.new.b
# If the redefinition added MI then /both/ would work.
# If such an implementation is found, please let me know!
(如果不引发所述 TypeError,我无法使上述工作正常进行。)