Skip to content

A simple library that exposes present? and blank? to common Ruby classes.

License

Notifications You must be signed in to change notification settings

joshwetzel/existence

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gem Version

Existence

Existence is a simple Ruby library that exposes Active Support's present? and blank? methods to the following classes:

  • Array
  • FalseClass
  • Hash
  • NilClass
  • String
  • TrueClass

It is intended to provide these helper methods to projects that do not include ActiveSupport. It is tested against the latest patch release for each minor version of Ruby 2.

Installation

In your Gemfile, include the existence gem and then bundle install.

gem 'existence'

Usage

The same patterns used in ActiveSupport can be expected with Existence.

  • An array is present if it has elements, and blank if it does not.

    [].present? # => false
    [].blank? # => true
    ['test'].present? # => true
    ['test'].blank? # => false
  • false is never present and always blank.

    false.present? # => false
    false.blank? # => true
  • A hash is present if it contains values, and blank if it does not.

    {}.present? # => false
    {}.blank? # => true
    { test: true }.present? # => true
    { test: true }.blank? # => false
  • nil is never present and always blank.

    nil.present? # => false
    nil.blank? # => true
  • A string is present if it contains non-whitespace characters, and blank if it does not.

    ''.present? # => false
    ''.blank? # => true
    'test'.present? # => true
    'test'.blank? # => false
  • true is always present and never blank.

    true.present? # => true
    true.blank? # => false

About

A simple library that exposes present? and blank? to common Ruby classes.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages