Sha256: 58e2d7498f9ec7bb9c8451c60dce490aa0663e1d864fe59de600eac5526c97b5

Contents?: true

Size: 798 Bytes

Versions: 10

Compression:

Stored size: 798 Bytes

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

  # Return a new module based on another. This includes the original module
  # into the new revised module.
  #
  #   module ReviseExample
  #     def foo; "foo"; end
  #   end
  #
  #   ReviseExample2 = ReviseExample.revise do
  #     alias_method :bar, :foo
  #   end
  #
  #   object = Object.new
  #   object.extend ReviseExample2
  #   object.bar  #=> 'foo'
  #
  # CREDIT: Trans

  def revise(&blk)
    base = self
    nm = Module.new{ include base }
    nm.class_eval(&blk)
    nm
  end

  alias_method :revisal, :revise
end

class Class
  undef_method :revise
  undef_method :revisal
end


Version data entries

10 entries across 9 versions & 2 rubygems

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