Issue #17938 has been updated by Eregon (Benoit Daloze).


Another problem is
```ruby
object.respond_to?(:symbol, include_all: false)
object.methods(regular: true)
```
does not solve anything.
It's unclear what `include_all` or `regular` mean without looking at the docs.
And if one looks at the docs, then they obviously can read positional argument names too, and there is no value to use keyword argumetns.

`only_public` for `respond_to?` is clearer, but it's the opposite value, which seems more confusing than helping.
`include_inherited` is clearer but seems way too long for anyone to type that.

I would think most people would never use the proposed kwarg form, it's simply too long for such core methods.

I would like to see more opinions from Ruby implementers, I would think most agree that the cost is not worth the small gain here.

> you cannot tell just looking at the method call what the parameter mean

This applies for any argument really. No other way than to read the docs (or know from a previous reading) to answer that precisely.

----------------------------------------
Feature #17938: Keyword alternative for boolean positional arguments
https://bugs.ruby-lang.org/issues/17938#change-92367

* Author: matheusrich (Matheus Richard)
* Status: Open
* Priority: Normal
----------------------------------------
Some Ruby methods accept optional boolean arguments. This kind of parameter is known to be confusing since you cannot tell just looking at the method call what the parameter mean. For example:

```ruby
object.respond_to?(:symbol, false) # what does `false` mean?
object.methods(true) # what does `true` mean?
```

Now compare that to

```ruby
object.respond_to?(:symbol, include_all: false)
object.methods(regular: true)
# or
object.methods(only_public: true)
# or
object.methods(include_all: false)
```

I know Matz doesn't like breaking changes, so maybe we could have both to not break current calls, but allow a nicer syntax in newer Ruby? I don't know the depths of the Ruby C implementation, so here's what I thought in plain Ruby:

```ruby
def respond_to?(symbol, include_all_positional=false, include_all: nil)
  include_all ||= include_all_positional

  # ...
end
```

I'm willing to tackle this, if approved.

---Files--------------------------------
Screenshot from 2021-06-06 11-37-44.png (5.63 KB)


-- 
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>