Project

General

Profile

Actions

Feature #13260

closed

Kernel#Boolean

Added by sawa (Tsuyoshi Sawada) about 7 years ago. Updated almost 7 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
[ruby-core:79809]

Description

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

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
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0