
Issue #20882 has been updated by austin (Austin Ziegler). bunnrf (RF Bunn) wrote in #note-6:
This was rejected 2 months ago https://bugs.ruby-lang.org/issues/20756
Previously https://bugs.ruby-lang.org/issues/13260
This is not about a Boolean type, but a Boolean coercion function, `Kernel#Boolean` or a casting function, `Object#to_bool`. I support the concept of a coercion function, but think that if string coercion is down, only case-insensitive true/false values should be supported and possibly 0/1 values. Under no circumstances should we make the NOrway mistake that YAML before 1.2 did. (I believe YAML 1.2 supports True, False, TRUE, FALSE, true, and false only.) This would be a good set, IMO. I don’t believe that the Rails / ActiveSupport approach is correct (although supporting symbol versions of the strings would be ok). ---------------------------------------- Feature #20882: Provide Boolean(...) https://bugs.ruby-lang.org/issues/20882#change-110566 * 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/