vm_method.c: add top-level ruby2_keywords
This is a top-level version of Module#ruby2_keywords. It can be used for functions (top-level methods) that delegates arguments. [Feature #16364]
This commit is contained in:
parent
5ad32d5504
commit
3a87826d0c
@ -2985,6 +2985,18 @@ class TestKeywordArguments < Test::Unit::TestCase
|
|||||||
assert_raise(FrozenError) { c.send(:ruby2_keywords, :baz) }
|
assert_raise(FrozenError) { c.send(:ruby2_keywords, :baz) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_top_ruby2_keywords
|
||||||
|
assert_in_out_err([], <<-INPUT, ["[1, 2, 3]", "{:k=>1}"], [])
|
||||||
|
def bar(*a, **kw)
|
||||||
|
p a, kw
|
||||||
|
end
|
||||||
|
ruby2_keywords def foo(*a)
|
||||||
|
bar(*a)
|
||||||
|
end
|
||||||
|
foo(1, 2, 3, k:1)
|
||||||
|
INPUT
|
||||||
|
end
|
||||||
|
|
||||||
def test_dig_kwsplat
|
def test_dig_kwsplat
|
||||||
kw = {}
|
kw = {}
|
||||||
h = {:a=>1}
|
h = {:a=>1}
|
||||||
|
15
vm_method.c
15
vm_method.c
@ -1947,6 +1947,19 @@ top_private(int argc, VALUE *argv, VALUE _)
|
|||||||
return rb_mod_private(argc, argv, rb_cObject);
|
return rb_mod_private(argc, argv, rb_cObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* call-seq:
|
||||||
|
* ruby2_keywords(method_name, ...) -> self
|
||||||
|
*
|
||||||
|
* For the given method names, marks the method as passing keywords through
|
||||||
|
* a normal argument splat. See Module#ruby2_keywords in detail.
|
||||||
|
*/
|
||||||
|
static VALUE
|
||||||
|
top_ruby2_keywords(int argc, VALUE *argv, VALUE module)
|
||||||
|
{
|
||||||
|
return rb_mod_ruby2_keywords(argc, argv, rb_cObject);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* module_function(symbol, ...) -> self
|
* module_function(symbol, ...) -> self
|
||||||
@ -2280,6 +2293,8 @@ Init_eval_method(void)
|
|||||||
"public", top_public, -1);
|
"public", top_public, -1);
|
||||||
rb_define_private_method(rb_singleton_class(rb_vm_top_self()),
|
rb_define_private_method(rb_singleton_class(rb_vm_top_self()),
|
||||||
"private", top_private, -1);
|
"private", top_private, -1);
|
||||||
|
rb_define_private_method(rb_singleton_class(rb_vm_top_self()),
|
||||||
|
"ruby2_keywords", top_ruby2_keywords, -1);
|
||||||
|
|
||||||
{
|
{
|
||||||
#define REPLICATE_METHOD(klass, id) do { \
|
#define REPLICATE_METHOD(klass, id) do { \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user