From: Trans Date: 2006-12-12T08:07:09+09:00 Subject: Re: bending ruby space ara.t.howard@noaa.gov wrote: > On Tue, 12 Dec 2006, Trans wrote: > > > 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"] ah. yes i know this pattern. though i prefer #class_extension myself. still not quite what i'm after but your sample helped jog my brain in the right direction --thanks. i *think* this does it: module CompressUtils module_function ... end module FileUtils include CompressUtils module_function *(CompressUtils.private_instance_methods & CompressUtils.methods(false)) end that seem about right? t.