Suppose you want to log every call to String#reverse while leaving its result alone. Give the existing method another name, redefine reverse to print a message, then call the saved name. Ruby’s alias keyword creates that second name; calling it does not change the method’s behavior or method lookup. section 13.2.3 section 13.2.1
class String
alias __old_reverse__ reverse
def reverse
$stderr.puts "Reversing a string!"
__old_reverse__
end
end
puts "David".reverse
The alias is created before reverse is redefined. The new reverse prints to STDERR, then calls __old_reverse__; that call supplies the return value. section 13.2.3
Ruby also provides Module#alias_method. Write `alias __old_reverse__ reverse` with bare names and no comma, or `alias_method :__old_reverse__, :reverse` with symbols. Unlike alias, alias_method is a method; it also accepts strings as arguments. section 13.2.3
Keeping the original available does not make every override safe. An override of Regexp#match can call an alias of the original and return an empty array when the original returns nil. Indexing a failed match then works, but an `if` test that previously detected failure now succeeds: an empty array is true, while nil is false. Preserve the original return behavior when callers rely on it. section 13.2.1





