Tag: 模块的

如何将类包含在类中

如何获取类中包含的模块数组,不包括那些通过inheritance传入的模块? 请注意, ancestors , included_modules将不起作用,因为它们的结果不区分包含在超类中预先添加的模块的模块。 换句话说,他们无法区分以下两种情况: M置于B的超类 class A; end class B [B, M, A, Object, Kernel, BasicObject] B M # => -1 B.included_modules # => [M, Kernel] M包含在B class A; end class B [B, M, A, Object, Kernel, BasicObject] B M # => -1 B.included_modules # => [M, Kernel]