Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Ruby中将几个模块同时包含到元类和普通类中_Ruby_Module - Fatal编程技术网

如何在Ruby中将几个模块同时包含到元类和普通类中

如何在Ruby中将几个模块同时包含到元类和普通类中,ruby,module,Ruby,Module,我有几个模块,比如Capybara::DSL、RSpec::Matchers、路由器、Common 我希望能够在代码中的任何地方使用这些模块中的方法。目前我试图做: module Helper # from http://stackoverflow.com/a/4663029/841064 module ClassMethods include Capybara::DSL include RSpec::Matchers include Router inc

我有几个模块,比如Capybara::DSL、RSpec::Matchers、路由器、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
您知道一种方法可以使所有这些方法在包含到模块或类中时都可以作为实例方法和类方法访问吗?

在要包含模块的类中同时使用include和extend如何

module Helper
  include Capybara::DSL
  include RSpec::Matchers
  include Router
  include Common
end

module A
  # Gives methods on instance
  include Helper

  # Gives methods on class
  extend Helper

  #...
end