I have several modules, say Capybara::DSL
, RSpec::Matchers
, Router
, Common
.
I'd want to be able to use methods from those modules nearly from anywhere in my code. Currently I attempted to do:
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
Then I'd want to use it as:
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
Do you know a method to get all those methods accessible as both instance and class methods when they are included to either module or class?