Sha256: 6b30b764fe985b9075804e052cd692e6f7e890ca06140918840b4506292918a0

Contents?: true

Size: 699 Bytes

Versions: 26

Compression:

Stored size: 699 Bytes

Contents

class Module

  # Define a shadow alias for a method.
  #
  #   class X
  #     shadow_method( :class )
  #   end
  #
  #   X.new.__class__  #=> X
  #
  def shadow_method( name, old_name=name )
    name, old_name = name.to_s, old_name.to_s
    shadow_name = '__' << name.gsub(/([=?!])$/, '') << '__' << $1.to_s
    alias_method( shadow_name, old_name )
  end

end


#  _____         _
# |_   _|__  ___| |_
#   | |/ _ \/ __| __|
#   | |  __/\__ \ |_
#   |_|\___||___/\__|
#
=begin test

  require 'test/unit'

  class TCModule < Test::Unit::TestCase

    class X
      shadow_method( :inspect )
    end

    def test_shadow_method
      assert( X.new.respond_to?(:__inspect__) )
    end

  end

=end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
facets-1.0.3 packages/core/lib/facet/module/shadow_method.rb
facets-0.9.0 lib/nano/module/shadow_method.rb
facets-1.0.0 lib/facet/module/shadow_method.rb
facets-1.3.0 lib/facets/core/module/shadow_method.rb
facets-1.1.0 lib/facet/module/shadow_method.rb
facets-1.2.0 lib/facets/core/module/shadow_method.rb
facets-1.2.1 lib/facets/core/module/shadow_method.rb
facets-1.3.2 lib/facets/core/module/shadow_method.rb
facets-1.3.1 lib/facets/core/module/shadow_method.rb
facets-1.3.3 lib/facets/core/module/shadow_method.rb
facets-1.4.2 lib/facets/core/module/shadow_method.rb
facets-1.4.1 lib/facets/core/module/shadow_method.rb
facets-1.4.0 lib/facets/core/module/shadow_method.rb
facets-1.4.3 lib/facets/core/module/shadow_method.rb
facets-1.4.4 lib/facets/core/module/shadow_method.rb
facets-1.4.5 lib/facets/core/module/shadow_method.rb
facets-1.7.0 lib/facets/core/module/shadow_method.rb
facets-1.7.30 lib/facets/core/module/shadow_method.rb
facets-1.7.38 lib/facets/core/module/shadow_method.rb
facets-1.7.46 lib/facets/core/module/shadow_method.rb