Sha256: 90f122d382ab969569444573ffe12e970bf7164403939af1c4c8d2dba6ac8710

Contents?: true

Size: 806 Bytes

Versions: 90

Compression:

Stored size: 806 Bytes

Contents

class Object
  # An object is blank if it's false, 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
    
  # An object is present if it's not blank.
  def present?
    !blank?
  end
end

class NilClass #:nodoc:
  def blank?
    true
  end
end

class FalseClass #:nodoc:
  def blank?
    true
  end
end

class TrueClass #:nodoc:
  def blank?
    false
  end
end

class Array #:nodoc:
  alias_method :blank?, :empty?
end

class Hash #:nodoc:
  alias_method :blank?, :empty?
end

class String #:nodoc:
  def blank?
    self !~ /\S/
  end
end

class Numeric #:nodoc:
  def blank?
    false
  end
end

Version data entries

90 entries across 87 versions & 20 rubygems

Version Path
davidlee-state-fu-0.2.0 lib/state_fu/active_support_lite/blank.rb
davidlee-state-fu-0.3.1 lib/state_fu/active_support_lite/blank.rb
p8-castronaut-0.6.1.1 vendor/activesupport/lib/active_support/core_ext/blank.rb
relevance-castronaut-0.6.0 vendor/activesupport/lib/active_support/core_ext/blank.rb
relevance-castronaut-0.6.1 vendor/activesupport/lib/active_support/core_ext/blank.rb
relevance-castronaut-0.7.4 vendor/activesupport/lib/active_support/core_ext/blank.rb
relevance-castronaut-0.7.5 vendor/activesupport/lib/active_support/core_ext/blank.rb
hash_rocket-0.4.1 lib/hash_rocket/object.rb
hash_rocket-0.4.0 lib/hash_rocket/object.rb
hash_rocket-0.3.9 lib/hash_rocket/object.rb
hash_rocket-0.3.8 lib/hash_rocket/object.rb
hash_rocket-0.3.7 lib/hash_rocket/object.rb
hash_rocket-0.3.6 lib/hash_rocket/object.rb
hash_rocket-0.3.5 lib/hash_rocket/object.rb
hash_rocket-0.3.4 lib/hash_rocket/object.rb
hash_rocket-0.3.3 lib/hash_rocket/object.rb
hash_rocket-0.3.2 lib/hash_rocket/object.rb
hash_rocket-0.3.1 lib/hash_rocket/object.rb
hash_rocket-0.3.0 lib/hash_rocket/object.rb
hash_rocket-0.2.9 lib/hash_rocket/object.rb