Skip to content

Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

Module#alias_method

alias_method(new_name, old_name) → symbol

Makes new_name a new copy of the method old_name. This can be used to retain access to methods that are overridden.

Example
module Mod
  alias_method :orig_exit, :exit #=> :orig_exit
  def exit(code=0)
    puts "Exiting with code #{code}"
    orig_exit(code)
  end
end
include Mod
exit(99)

produces:

Example
Exiting with code 99

Ruby version changes

  1. 3.0
See also #>= #ancestors #> #append_features also in 4.1 · 4.0 · 3.4 · 3.2 · 3.1 · 3.0