1

我在课堂上包含了两个不同的模块库。两者都有方法test_method。我如何明确地使用一个而不是另一个?

class User
include Calculus::Math #a module
include Algebra::Math::Misc #a module

#perform_test is defined in both Calculus::Math and Algebra::Math::Misc
perform_test: 1 

#Calculus::Math::perform_test: 1 #This doesn't work

end

谢谢

4

2 回答 2

0

如果元编程,您将不得不做一些事情:

(Calculus::Math).method(:perform_test).bind(self).call 1

或者

include Calculus::Math
alias :foo :perform_test
include ...

我没有测试过这些,可能会犯一些小错误。

于 2012-10-27T23:37:13.597 回答
0

尝试perform_testCalculus::Math.

Calculus::Math.module_eval do
  module_function(:perform_test)
  public :perform_test
end

class User
  include Calculus::Math #a module
  include Algebra::Math::Misc #a module

  Calculus::Math.perform_test(1)
end
于 2012-10-27T23:49:16.787 回答