Exactly. Here let me give an actual example to help explain:
module CompressUtils
module_function
def tar_gz( folder, to_file=nil )
# ...
end
end
I need CompressUtils to stay as is so as to work on it's own as a
function module. But in one case I was thinking of doing:
module FileUtils
include_extend_or_whatever CompressUtils
end
With the desired effect being is as if I had originially done:
module FileUtils
module_function
def tar_gz( folder, to_file=nil )
# ...
end
end
t.
ah. i use this alot, it's concise and extremely powerful:
harp:~ > cat a.rb
module CompressUtils
module Methods
def tar_gz folder, to_file=nil
p [ folder, to_file ]
end
end
module ClassMethods
include Methods
end
module InstanceMethods
include Methods
end
def self.included other
other.module_eval{
include InstanceMethods if defined? InstanceMethods
extend ClassMethods if defined? ClassMethods
def self.included other
other.module_eval{
include InstanceMethods if defined? InstanceMethods
extend ClassMethods if defined? ClassMethods
}
end
}
end
end
module FileUtils
include CompressUtils
end
FileUtils.tar_gz '/', 'a.tgz'
include FileUtils
tar_gz '/', 'a.tgz'
self.class.tar_gz '/', 'a.tgz'
harp:~ > ruby a.rb
["/", "a.tgz"]
["/", "a.tgz"]
["/", "a.tgz"]