From: shevegen@... Date: 2017-02-28T11:11:10+00:00 Subject: [ruby-core:79819] [Ruby trunk Feature#13260] Kernel#Boolean Issue #13260 has been updated by Robert A. Heiler. > 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. I agree. :) Not saying that I agree with the API, it feels a bit cumbersome; but I agree with the comment above. By the way, I think the first two cases are the one that are the least ambiguous since they only evaluate the two strings "true" and "false" into the respective true and false representation: Boolean("true") # => true Boolean("false") # => false (The name "Boolean" is a bit strange though... where does this reside then? In Kernel? Why not to_bool or to_boolean? Though admittedly the latter also includes the word "boolean", I guess the uppercased leading part confuses me a bit. I am aware of Kernel#Integer() or whever it resides, but I think that in general it may be better to not use too many upcased method names; in ruby we have a lot of flexibility like .Foo() or class Foo; Foo[] - but anyway, this is a side comment, as written above I agree with what Tsuyoshi Sawada stated :) ) ---------------------------------------- Feature #13260: Kernel#Boolean https://bugs.ruby-lang.org/issues/13260#change-63255 * 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: