Issue #16356 has been updated by jeremyevans0 (Jeremy Evans).


zverok (Victor Shepelev) wrote:
> `#inspect` just follows whatever `#parameters` say. 
> 
> But I indeed find that `#parameters` return value is kinda weird for this case:
> 
> ```
> ./ruby --disable-gems -e "def m(...); end; p method(:m).parameters"
> [[:rest, :*], [:block, :&]]
> ```
> E.g., literally, "parameter of the *type* `:rest`, *named* `*`, and parameter of the *type* `:block`, *named* `&`".
> 
> I believe that a proper return value for parameters in this case would be, probably
> ```ruby
> [[:rest], [:keyrest], [:block]]
> ```
> If it would be so (and it seems reasonable), `#inspect` will return `#m(*, **, &)`

That's not how `...` is implemented, though.  It is implemented so that:

```ruby
def a(...)
  b(...)
end
```

means

```ruby
ruby2_keywords def a(*args, &block)
  b(*args, &block)
end
```

other than the local variable names.  So the current behavior omitting `:keyrest` makes sense.  The local variable names should not be included, so the `parameters` output should probably be `[[:rest], [:block]]`.

This does raise a question of whether methods flagged with `ruby2_keywords` should have their `parameters` output reflect that.  I'm not sure whether that is worth doing, but if so, we should probably replace `:rest` with something like `:restkw`.

----------------------------------------
Feature #16356: Method#inspect of argument forwarding
https://bugs.ruby-lang.org/issues/16356#change-82743

* Author: znz (Kazuhiro NISHIYAMA)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
Current behavior includes `(**, &&)`.
Is this intentional?

```
% ruby -e 'def mf(...);end;p method(:mf)'
#<Method: main.mf(**, &&) -e:1>
```

I added tests of current behavior at https://github.com/ruby/ruby/commit/777973084e599cf9efa490173709b187fb507f90



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>