Argument forwarding with `...` now supports leading arguments.

```ruby
def method_missing(meth, ...)
  send(:"do_#{meth}", ...)
end
```
parent 2e9b8f0d
......@@ -2397,6 +2397,22 @@ paren_args : '(' opt_call_args ')'
{
$$ = $2;
}
| '(' args comma tBDOT3 rparen
{
#if 1
mrb_sym r = MRB_OPSYM(mul);
mrb_sym b = MRB_OPSYM(and);
$$ = cons(push($2, new_splat(p, new_lvar(p, r))),
new_block_arg(p, new_lvar(p, b)));
#else
mrb_sym r = MRB_OPSYM(mul);
mrb_sym k = MRB_OPSYM(pow);
mrb_sym b = MRB_OPSYM(and);
$$ = cons(list2(push($2, new_splat(p, new_lvar(p, r))),
new_kw_hash(p, list1(cons(new_kw_rest_args(p, 0), new_lvar(p, k))))),
new_block_arg(p, new_lvar(p, b)));
#endif
}
| '(' tBDOT3 rparen
{
#if 1
......@@ -3493,6 +3509,24 @@ f_arglist_paren : '(' f_args rparen
p->lstate = EXPR_BEG;
p->cmd_start = TRUE;
}
| '(' f_arg ',' tBDOT3 rparen
{
#if 1
/* til real keyword args implemented */
mrb_sym r = MRB_OPSYM(mul);
mrb_sym b = MRB_OPSYM(and);
local_add_f(p, r);
$$ = new_args(p, $2, 0, r, 0,
new_args_tail(p, 0, 0, b));
#else
mrb_sym r = MRB_OPSYM(mul);
mrb_sym k = MRB_OPSYM(pow);
mrb_sym b = MRB_OPSYM(and);
local_add_f(p, r); local_add_f(p, k);
$$ = new_args(p, $2, 0, r, 0,
new_args_tail(p, 0, new_kw_rest_args(p, nsym(k)), b));
#endif
}
| '(' tBDOT3 rparen
{
#if 1
......
This diff is collapsed.
......@@ -686,3 +686,22 @@ assert('_0 is not numbered parameter') do
_0 = :l
assert_equal(:l, ->{_0}.call)
end
assert('argument forwarding') do
c = Class.new {
def a0(*a,&b)
assert_equal([1,2,3], a)
assert_not_nil(b)
end
def a(...)
a0(...)
end
def b(a,...)
assert_equal(a,1)
a0(1,...)
end
}
o = c.new
o.a(1,2,3){}
o.b(1,2,3){}
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment