mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Feature 17314: alias_method returns symbol
This commit is contained in:
parent
34f6b22df0
commit
51bcd50915
3 changed files with 21 additions and 6 deletions
3
NEWS.md
3
NEWS.md
|
@ -253,6 +253,9 @@ Outstanding ones only.
|
||||||
methods now return array of defined methods names as symbols.
|
methods now return array of defined methods names as symbols.
|
||||||
[[Feature #17314]]
|
[[Feature #17314]]
|
||||||
|
|
||||||
|
* Module#alias_method now returns the defined alias as symbol.
|
||||||
|
[[Feature #17314]]
|
||||||
|
|
||||||
* Mutex
|
* Mutex
|
||||||
|
|
||||||
* `Mutex` is now acquired per-`Fiber` instead of per-`Thread`. This change
|
* `Mutex` is now acquired per-`Fiber` instead of per-`Thread`. This change
|
||||||
|
|
|
@ -85,8 +85,19 @@ describe "Module#alias_method" do
|
||||||
Module.should have_public_instance_method(:alias_method, false)
|
Module.should have_public_instance_method(:alias_method, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns self" do
|
describe "returned value" do
|
||||||
@class.send(:alias_method, :checking_return_value, :public_one).should equal(@class)
|
ruby_version_is ""..."3.0" do
|
||||||
|
it "returns self" do
|
||||||
|
@class.send(:alias_method, :checking_return_value, :public_one).should equal(@class)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
ruby_version_is "3.0" do
|
||||||
|
it "returns symbol of the defined method name" do
|
||||||
|
@class.send(:alias_method, :checking_return_value, :public_one).should equal(:checking_return_value)
|
||||||
|
@class.send(:alias_method, 'checking_return_value', :public_one).should equal(:checking_return_value)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "works in module" do
|
it "works in module" do
|
||||||
|
|
|
@ -1941,13 +1941,13 @@ rb_alias(VALUE klass, ID alias_name, ID original_name)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* alias_method(new_name, old_name) -> self
|
* alias_method(new_name, old_name) -> symbol
|
||||||
*
|
*
|
||||||
* Makes <i>new_name</i> a new copy of the method <i>old_name</i>. This can
|
* Makes <i>new_name</i> a new copy of the method <i>old_name</i>. This can
|
||||||
* be used to retain access to methods that are overridden.
|
* be used to retain access to methods that are overridden.
|
||||||
*
|
*
|
||||||
* module Mod
|
* module Mod
|
||||||
* alias_method :orig_exit, :exit
|
* alias_method :orig_exit, :exit #=> :orig_exit
|
||||||
* def exit(code=0)
|
* def exit(code=0)
|
||||||
* puts "Exiting with code #{code}"
|
* puts "Exiting with code #{code}"
|
||||||
* orig_exit(code)
|
* orig_exit(code)
|
||||||
|
@ -1968,8 +1968,9 @@ rb_mod_alias_method(VALUE mod, VALUE newname, VALUE oldname)
|
||||||
if (!oldid) {
|
if (!oldid) {
|
||||||
rb_print_undef_str(mod, oldname);
|
rb_print_undef_str(mod, oldname);
|
||||||
}
|
}
|
||||||
rb_alias(mod, rb_to_id(newname), oldid);
|
VALUE id = rb_to_id(newname);
|
||||||
return mod;
|
rb_alias(mod, id, oldid);
|
||||||
|
return ID2SYM(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
Loading…
Add table
Reference in a new issue