
Issue #20882 has been updated by duerst (Martin Dürst). Earlopain (A S) wrote in #note-5:
I'm positive and would like to use something like this as well. However, since `ActiveRecord::Type::Boolean` from Rails has come up, which values should be considered `true`?
There are quite a few possible combinations: * 0 and 1 * "0" and "1" * "true" and "false" * "t" and "f" * various other boolean-like words, like "yes"/"no", "on"/"off" * symbols * a variety of different capitalizations of these
For reference, here is the list that rails currently considers "false": https://github.com/rails/rails/blob/852d0cd4123463cf215f4b024801b256857295c4...
I think we shouldn't mix program-internal conversions and human-language choices. Anything like the following (very rough/quick translations) will not work: ```ruby puts "Antwort: Ja oder nein?" # German p Boolean(gets.chomp) puts "Reponse: Si ou non?" # French p Boolean(gets.chomp) puts "解答: はいまたはいいえ?" # Japanese p Boolean(gets.chomp) ``` ---------------------------------------- Feature #20882: Provide Boolean(...) https://bugs.ruby-lang.org/issues/20882#change-110572 * Author: getajobmike (Mike Perham) * Status: Open ---------------------------------------- Ruby provides Integer(...) and Float(...) global methods to coerce values. Is there a similar method for Booleans? I'd like to do something like: ``` # ENV["SOME_FEATURE"] is unset Boolean(ENV["SOME_FEATURE"]) # => false # ENV["SOME_FEATURE"] is unset, but allow a default? Boolean(ENV["SOME_FEATURE"], true) # => true # explicitly disable ENV["SOME_FEATURE"] = "0" Boolean(ENV["SOME_FEATURE"], true) # => false # explicitly enable ENV["SOME_FEATURE"] = "1" Boolean(ENV["SOME_FEATURE"]) # => true ``` -- https://bugs.ruby-lang.org/