From: sawadatsuyoshi@... Date: 2019-07-13T03:28:21+00:00 Subject: [ruby-core:93735] [Ruby master Bug#15987] Let `exception` option in `Kernel#Complex`, `Kernel#Float`, `Kernel#Integer`, `Kernel#Rational` be falsy vs. truthy Issue #15987 has been updated by sawa (Tsuyoshi Sawada). nobu (Nobuyoshi Nakada) wrote: > As for optional parameters, there are some inconsistencies. > ... > And other methods fall back `nil` to the default value, e.g., `File.open`. I came up with another alternative. Since this is about suppressing an exception, I think the concept is close to the optional second argument/block of `Hash#fetch`. One is keyword argument and the other is positional argument, but that does not mean that the values should behave differently. I think we can imitate it. That is, when the explicit `exception` option is given, then that value should be returned instead of raising an error when the string cannot be parsed correctly. This would be a breaking change, but I do not think it will break much existing code because most use cases so far probably only use the `exception` option with the value `false`, in which case it currently returns `nil`, and my proposal would change that to return `false`, but I do not think that is a big deal. ---------------------------------------- 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-79372 * 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: