diff options
author | Radosław Bułat <radek.bulat@gmail.com> | 2020-12-18 19:17:57 +0100 |
---|---|---|
committer | Yusuke Endoh <mame@ruby-lang.org> | 2020-12-19 18:19:49 +0900 |
commit | eb8ea336d33af7e1dec4c17964c671c33cf75ce1 (patch) | |
tree | 0d093c71f75825dbc5ebfcb3b74bb6fad6250bf9 /vm_method.c | |
parent | 8148f88b92a6b8d850b991afe74fb0d0f9c11887 (diff) |
Feature 17314: allow to pass array to public, protected and private methods
Diffstat (limited to 'vm_method.c')
-rw-r--r-- | vm_method.c | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/vm_method.c b/vm_method.c index 1546722b14..1fbb481b50 100644 --- a/vm_method.c +++ b/vm_method.c @@ -1974,6 +1974,16 @@ rb_mod_alias_method(VALUE mod, VALUE newname, VALUE oldname) } static void +check_and_export_method(VALUE self, VALUE name, rb_method_visibility_t visi) +{ + ID id = rb_check_id(&name); + if (!id) { + rb_print_undef_str(self, name); + } + rb_export_method(self, id, visi); +} + +static void set_method_visibility(VALUE self, int argc, const VALUE *argv, rb_method_visibility_t visi) { int i; @@ -1985,13 +1995,19 @@ set_method_visibility(VALUE self, int argc, const VALUE *argv, rb_method_visibil return; } - for (i = 0; i < argc; i++) { - VALUE v = argv[i]; - ID id = rb_check_id(&v); - if (!id) { - rb_print_undef_str(self, v); + + VALUE v; + + if (argc == 1 && (v = rb_check_array_type(argv[0])) != Qnil) { + long j; + + for (j = 0; j < RARRAY_LEN(v); j++) { + check_and_export_method(self, RARRAY_AREF(v, j), visi); } - rb_export_method(self, id, visi); + } else { + for (i = 0; i < argc; i++) { + check_and_export_method(self, argv[i], visi); + } } } @@ -2013,6 +2029,7 @@ set_visibility(int argc, const VALUE *argv, VALUE module, rb_method_visibility_t * public -> self * public(symbol, ...) -> self * public(string, ...) -> self + * public(array) -> self * * With no arguments, sets the default visibility for subsequently * defined methods to public. With arguments, sets the named methods to @@ -2031,6 +2048,7 @@ rb_mod_public(int argc, VALUE *argv, VALUE module) * protected -> self * protected(symbol, ...) -> self * protected(string, ...) -> self + * protected(array) -> self * * With no arguments, sets the default visibility for subsequently * defined methods to protected. With arguments, sets the named methods @@ -2058,6 +2076,7 @@ rb_mod_protected(int argc, VALUE *argv, VALUE module) * private -> self * private(symbol, ...) -> self * private(string, ...) -> self + * private(array) -> self * * With no arguments, sets the default visibility for subsequently * defined methods to private. With arguments, sets the named methods |