私はいくつかのモジュールを持っています、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
モジュールまたはクラスのいずれかに含まれている場合に、インスタンスメソッドとクラスメソッドの両方としてこれらすべてのメソッドにアクセスできるようにするメソッドを知っていますか?