Sha256: e0d98ec4c9aecb62944edc75822801890727cdfd7181ee19cd1d92c3dafba9dc

Contents?: true

Size: 585 Bytes

Versions: 10

Compression:

Stored size: 585 Bytes

Contents

class Module

  private

  # Aliases a method and undefines the original.
  #
  #   class RenameExample
  #     def foo; "foo"; end
  #     rename_method(:bar, :foo)
  #   end
  # 
  #   example = RenameExample.new
  #   example.bar  #=> 'foo'
  #
  #   expect NoMethodError do
  #     example.foo
  #   end
  #
  # CREDIT: Trans

  def rename_method( to_sym, from_sym )
    raise ArgumentError, "method #{from_sym} does not exist" unless method_defined?( from_sym )
    alias_method( to_sym, from_sym )
    undef_method( from_sym )
  end

  alias_method :rename, :rename_method

end

Version data entries

10 entries across 9 versions & 2 rubygems

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