[#79532] Immutable Strings vs Symbols — Daniel Ferreira <subtileos@...>

Hi,

15 messages 2017/02/15

[ruby-core:79813] [Ruby trunk Feature#13260] Kernel#Boolean

From: sawadatsuyoshi@...
Date: 2017-02-28 06:20:31 UTC
List: ruby-core #79813
Issue #13260 has been updated by Tsuyoshi Sawada.


I agree that the proposal was vague. Instead of using `strict`, perhaps we can pass an argument or arguments expressing the language/mode that we want to allow.

```ruby
Boolean("はい", allow: ["JA", "EN"])
```


----------------------------------------
Feature #13260: Kernel#Boolean
https://bugs.ruby-lang.org/issues/13260#change-63248

* Author: Tsuyoshi Sawada
* Status: Feedback
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I think we have lots of occasions to receive a `true` or `false` value as a string input, and want to convert it to `true` or `false`. Perhaps we can have a method `Kernel#Boolean` in a similar spirit to `Kernel#Integer` and its kins, which takes an optional keyword argument `exception` (similar to https://bugs.ruby-lang.org/issues/12732) and `strict` (defaulted to true).

```ruby
Boolean("true") # => true
Boolean("false") # => false
Boolean("foo") # => ArgumentError
Boolean("foo", exception: nil) # => nil
Boolean("1") # => ArgumentError
Boolean("1", strict: false) # => true
Boolean("yes", strict: false) # => true
Boolean("0", strict: false) # => false
Boolean("no", strict: false) # => false
Boolean("foo", strict: false, 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>

In This Thread

Prev Next