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
vm_method.c
View on GitHub ↗
static VALUE
rb_mod_alias_method(VALUE mod, VALUE newname, VALUE oldname)
{
ID oldid = rb_check_id(&oldname);
if (!oldid) {
rb_print_undef_str(mod, oldname);
}
VALUE id = rb_to_id(newname);
rb_alias(mod, id, oldid);
return ID2SYM(id);
}
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
-
3.0
-
Module#alias_methodnow returns the defined alias as a symbol. [Feature #17314]
-