From: "ioquatix (Samuel Williams) via ruby-core" Date: 2024-11-09T00:19:34+00:00 Subject: [ruby-core:119854] [Ruby master Feature#20882] Provide Boolean(...) Issue #20882 has been updated by ioquatix (Samuel Williams). I am the current maintainer of the `boolean` gem. You can check the implementation here: https://github.com/ioquatix/boolean I think `Boolean` can be adopted as a core Ruby class, but I think it has been discussed before and rejected because it only has two values. However, for type annotation and type coercion, it can be useful. ---------------------------------------- Feature #20882: Provide Boolean(...) https://bugs.ruby-lang.org/issues/20882#change-110544 * 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/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/