Class: Object

Inherits:
BasicObject
Defined in:
lib/croesus/core_ext/blank.rb

Overview

Add #blank? and #present? methods to Object class.

Instance Method Summary collapse

Instance Method Details

#blank?TrueClass, FalseClass

Returns true if the object is nil or empty (if applicable)

[].blank?         #=>  true
[1].blank?        #=>  false
[nil].blank?      #=>  false

Returns:



30
31
32
# File 'lib/croesus/core_ext/blank.rb', line 30

def blank?
  nil? || (respond_to?(:empty?) && empty?)
end

#present?TrueClass, FalseClass

Returns true if the object is NOT nil or empty

[].present?         #=>  false
[1].present?        #=>  true
[nil].present?      #=>  true

Returns:



42
43
44
# File 'lib/croesus/core_ext/blank.rb', line 42

def present?
  !blank?
end