Class: Object

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

Instance Method Summary collapse

Instance Method Details

#blank?Boolean

An object is blank if it’s nil, empty, or a whitespace string. For example, “”, “ ”, nil, [], and {} are blank.

This simplifies

if !address.nil? && !address.empty?

to

if !address.blank?

Returns:

  • (Boolean)


9
10
11
12
13
14
15
16
17
# File 'lib/airake/core_ext/blank.rb', line 9

def blank?
  if respond_to?(:empty?) && respond_to?(:strip)
    empty? or strip.empty?
  elsif respond_to?(:empty?)
    empty?
  else
    !self
  end
end