Method: Module#rename_method

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

#rename_method(to_sym, from_sym) ⇒ Object (private) Also known as: rename

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

Raises:

  • (ArgumentError)


21
22
23
24
25
# File 'lib/core/facets/module/rename_method.rb', line 21

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