#require 'facets/core/module/revisal' require 'facets/core/module/rename' require 'facets/core/module/redef' require 'facets/core/module/remove' require 'facets/core/module/nodef' require 'facets/core/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