Project

General

Profile

Actions

Feature #20882

open

Provide Boolean(...)

Added by getajobmike (Mike Perham) 7 days ago. Updated 4 days ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:119852]

Description

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

Related issues 6 (0 open6 closed)

Related to Ruby master - Feature #20756: Introduce Boolean classRejectedActions
Related to Ruby master - Feature #14224: Boolean classRejectedActions
Related to Ruby master - Feature #13260: Kernel#BooleanRejectedActions
Related to Ruby master - Feature #17265: Add `Bool` moduleFeedbackmatz (Yukihiro Matsumoto)Actions
Related to Ruby master - Bug #12827: Add Boolean data type.RejectedActions
Related to Ruby master - Feature #12515: Create "Boolean" superclass of TrueClass / FalseClassRejectedActions
Actions

Also available in: Atom PDF

Like6
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like1Like0Like0Like0Like0Like0Like0