[ruby-core:93722] [Ruby master Bug#15987] Let `exception` option in `Kernel#Complex`, `Kernel#Float`, `Kernel#Integer`, `Kernel#Rational` be falsy vs. truthy
From:
eregontp@...
Date:
2019-07-12 13:31:46 UTC
List:
ruby-core #93722
Issue #15987 has been updated by Eregon (Benoit Daloze).
matz (Yukihiro Matsumoto) wrote:
> Options are:
>
> * accept normal truthy/falsey value for boolean (using `RTEST()`)
> * accept `true`/`false` for boolean; exception for everything else
>
> And we should keep consistency.
Both sound fine to me.
nobu implemented the second option.
We can try to keep consistency in the future,
but I think we can't easily change existing methods taking a truthy/falsey argument for compatibility.
----------------------------------------
Bug #15987: Let `exception` option in `Kernel#Complex`, `Kernel#Float`, `Kernel#Integer`, `Kernel#Rational` be falsy vs. truthy
https://bugs.ruby-lang.org/issues/15987#change-79355
* Author: sawa (Tsuyoshi Sawada)
* Status: Closed
* Priority: Normal
* Assignee:
* Target version:
* ruby -v:
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
The `exception` option in `Kernel#Complex`, `Kernel#Float`, `Kernel#Integer`, and `Kernel#Rational` distinguishes `false` vs. other values.
```ruby
Integer("z", exception: false) #=> nil
Integer("z", exception: nil) #>> ArgumentError: invalid value for Integer(): "z")
```
But in most other cases where a boolean notion is concerned (for example, the `chomp` option in `Kernel#gets`), the distinction is between falsy vs. truthy values.
I request the distinction to be falsy vs. truthy. In other words, I would like the value `nil` to work on the falsy side rather than the truthy side like this.
```ruby
Integer("z", exception: false) #=> nil
Integer("z", exception: nil) #=> nil
```
--
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>