Handy-dandy helpers to convert arbitrary values to booleans in an intuitive way.
Ruby Gherkin
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
features
lib
.document
.gitignore
.pelusa.yml
.yardopts
CHANGELOG.md
Gemfile
Gemfile.lock
LICENSE
README.md
Rakefile
VERSION
cucumber.yml
to_bool.gemspec

README.md

to_bool

Summary

This gem extends various classes to provide a simple and intuitive to_bool operator that tends to Do What You Mean when retrieving a value from an ENV var or from an HTTP request and treating it as a boolean.

For example:

false, "false", "f", "no", "n", "0", "", and nil are all considered false whereas true, "true", "t", "yes", "y", "1", etc are all considered true.

Instances of FalseClass and TrueClass remain the same, and Fixnum is overridden such that 0 is considered false but all other values are considered true.

See the (very very short) source code for exact details.

Installation and Usage

Install the gem:

gem install to_bool

Or if you're using bundler, add this line to your Gemfile and run bundle install:

gem 'to_bool'

From there, any object should respond to .to_bool in a meaningful way.