我有几个模块,比如Capybara::DSL
, RSpec::Matchers
, Router
, Common
。
我希望能够在我的代码中几乎任何地方使用这些模块中的方法。目前我试图做:
module Helper
# from http://stackoverflow.com/a/4663029/841064
module ClassMethods
include Capybara::DSL
include RSpec::Matchers
include Router
include Common
end
include Capybara::DSL
include RSpec::Matchers
include Router
include Common
extend ClassMethods
def self.included(other)
other.extend(ClassMethods)
end
end
然后我想用它作为:
module A
include Helper
class << self
# all methods from 4 modules are available in all methods here
end
# all methods from 4 modules are available in all methods here
end
class B
include Helper
class << self
# all methods from 4 modules are available in all methods here
end
# all methods from 4 modules are available in all methods here. But they aren't available here
end
您是否知道一种方法可以在将所有这些方法包含到模块或类中时作为实例和类方法访问它们?