#require 'facet/module/revisal' require 'facet/module/rename' require 'facet/module/redef' require 'facet/module/remove' require 'facet/module/nodef' require 'facet/module/wrap' # Using integrate is just like using include except the # module included is a reconstruction of the one given # altered by the commands given in the block. # # Convenient commands available are: #rename, #redef, # #remove, #nodef and #wrap. But any module method # can be used. # # module W # def q ; "q" ; end # def y ; "y" ; end # end # # class X # integrate W do # nodef :y # end # end # # x = X.new # x.q #=> "q" # x.y #=> missing method error # # This is like #revisal, but #revisal only # returns the reconstructred module. It does not # include it. class Module def integrate( mod, &block ) #include mod.revisal( &blk ) m = Module.new { include mod } m.class_eval &block include m end end # _____ _ # |_ _|__ ___| |_ # | |/ _ \/ __| __| # | | __/\__ \ |_ # |_|\___||___/\__| # =begin testing require 'test/unit' class TCModule < Test::Unit::TestCase module M def x ; 1 ; end end class C integrate M do rename :y, :x end end def test_integrate c = C.new assert_raises( NoMethodError ) { c.x } assert_equal( 1, c.y ) end end =end