There is a trick if you have access to the modules source, and there's still a trick if you don't. If you do, this would be the module A
:
module A
def a
puts 'a!'
end
module_function :a
end
All of these will call a
:
A.a
include A; a
Even if you don't have access to the module's source, this is still possible with a little (lot) of metaprogramming:
SomeMod.instance_methods(false).each {|method| SomeMod.__send__(:module_function, method.to_sym)}
This only works if the methods are defined as instance methods only in the original module.
If you want do define them as class methods and only make the instance when included:
module A
def self.a
puts 'a'
end
def self.included(klass)
A.singleton_class.instance_methods(false).each do |m|
klass.__send__(:define_method, m.to_sym) do |*args|
A.__send__(m.to_sym, *args)
end
end
end
end