Project

existence

0.0
No release in over 3 years
Low commit activity in last 3 years
Exposes present? and blank? to common Ruby classes.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 13
 Project Readme

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