Sha256: 25067371a9c5431f7c58341ab04045f7ae0a80f1f3cd5eb78296079c25ba749f

Contents?: true

Size: 816 Bytes

Versions: 17

Compression:

Stored size: 816 Bytes

Contents

# = Blank
#
# Core extension method #blank? added to core clesses.

#
module Kernel
  # 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?
  def blank?
    respond_to?(:empty?) ? empty? : !self
  end
end

class NilClass
  def blank?
    true
  end
end

class FalseClass
  def blank?
    true
  end
end

class TrueClass
  def blank?
    false
  end
end

class Array
  alias_method :blank?, :empty?
end

class Hash
  alias_method :blank?, :empty?
end

class String
  # Is this string just whitespace?
  #
  #   "abc".blank?  #=> false
  #   "   ".blank?  #=> true
  def blank?
    self !~ /\S/
  end
end

class Numeric
  def blank?
    false
  end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
facets-2.8.4 lib/core/facets/blank.rb
facets-2.8.3 lib/core/facets/blank.rb
facets-2.8.2 lib/core/facets/blank.rb
facets-2.8.1 lib/core/facets/blank.rb
facets-2.8.0 lib/core/facets/blank.rb
facets-2.7.0 lib/core/facets/blank.rb
facets-2.6.0 lib/core/facets/blank.rb
facets-2.4.0 lib/facets/blank.rb
facets-2.4.1 lib/facets/blank.rb
facets-2.4.4 lib/core/facets/blank.rb
facets-2.4.2 lib/core/facets/blank.rb
facets-2.4.3 lib/core/facets/blank.rb
facets-2.5.1 lib/core/facets/blank.rb
facets-2.5.0 lib/core/facets/blank.rb
facets-2.4.5 lib/core/facets/blank.rb
facets-2.5.2 lib/core/facets/blank.rb
mack-facets-0.8.2 lib/gems/facets-2.4.5/lib/core/facets/blank.rb