BooleanClass

Build Status Dependency Status Code Climate

Description

Performs type conversion from anything to true:TrueClass / false:FalseClass

Boolean(0.0)         #=> true
FalseClass < Boolean #=> true

Anti-Features

Similar to boolean gem but:

  • Without parse_bool()
  • Without raising exceptions
  • Without to_bool() to_b() methods
  • Does not pollute Object or Kernel; polite monkey patching with include BooleanClass::Conversion

Installation

$ gem install boolean_class or add to your Gemfile this line: gem 'boolean_class' then run bundle install

Usage

Just require 'boolean_class' and then use it as:

As a conversion method Boolean()

require 'boolean_class'

# Example true values
Boolean(true)  #=> true
Boolean(999)   #=> true
Boolean(0)     #=> true

# Example false values
Boolean(false) #=> false
Boolean(nil)   #=> false

As data type checking / validation

require 'boolean_class'

# Instance type checking
true.is_a?(Boolean)   #=> true
false.is_a?(Boolean)  #=> true
0.is_a?(Boolean)      #=> false
nil.is_a?(Boolean)    #=> false
(0==1).is_a?(Boolean) #=> true

# Class type checking
Object < Boolean      #=> nil (false)
NilClass < Boolean    #=> nil (false)
Class < Boolean       #=> nil (false)
TrueClass < Boolean   #=> true
FalseClass < Boolean  #=> true

Contributing

  1. Fork it.
  2. Make your feature addition or bug fix and create your feature branch.
  3. Update the Change Log.
  4. Add specs/tests for it. This is important so I don't break it in a future version unintentionally.
  5. Commit, create a new Pull Request.
  6. Check that your pull request passes the build.

License

Released under the MIT License. See the LICENSE file for further details.

RubyGems | Documentation | Source | Bugtracker | Build Status | Dependency Status | Code Climate