Sha256: 1ba00b50da9cb69b3aecfa221f3a0851ebb56998c797202687f79d95b0c56bba

Contents?: true

Size: 1.09 KB

Versions: 10

Compression:

Stored size: 1.09 KB

Contents

require 'facets/module/redirect_method'
require 'facets/module/redefine_method'
require 'facets/module/rename_method'
require 'facets/module/wrap_method'
require 'facets/module/nodef'

class Module

  # 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

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

end

Version data entries

10 entries across 9 versions & 2 rubygems

Version Path
facets-glimmer-3.2.0 lib/core/facets/module/integrate.rb
facets-3.1.0 lib/core/facets/module/integrate.rb
facets-3.0.0 lib/core/facets/module/integrate.rb
facets-2.9.3 lib/core/facets/module/integrate.rb
facets-2.9.2 lib/core/facets/module/integrate.rb
facets-2.9.2 src/core/facets/module/integrate.rb
facets-2.9.1 lib/core/facets/module/integrate.rb
facets-2.9.0 lib/core/facets/module/integrate.rb
facets-2.9.0.pre.2 lib/core/facets/module/integrate.rb
facets-2.9.0.pre.1 lib/core/facets/module/integrate.rb