Method: Module#integrate

Defined in:
lib/core/facets/module/integrate.rb

#integrate(mod, &block) ⇒ Object

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 IntegrateExampleModule
  def q ; "q" ; end
  def y ; "y" ; end
end

class InegrateExampleClass
  integrate IntegrateExampleModule do
    undef_method :y
  end
end

x = InegrateExampleClass.new
x.q  #=> "q"

expect NameError do
  x.y
end

This is like #revisal, but #revisal only returns the reconstructred module. It does not include it.

CREDIT: Trans



41
42
43
44
45
46
# File 'lib/core/facets/module/integrate.rb', line 41

def integrate(mod, &block)
  #include mod.revisal( &blk )
  m = Module.new{ include mod }
  m.class_eval(&block)
  include m
end