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
hash_rocket-0.2.8 lib/hash_rocket/object.rb
hash_rocket-0.2.7 lib/hash_rocket/object.rb
hash_rocket-0.2.6 lib/hash_rocket/object.rb
hash_rocket-0.2.5 lib/hash_rocket/object.rb
hash_rocket-0.2.4 lib/hash_rocket/object.rb
hash_rocket-0.2.3 lib/hash_rocket/object.rb
radiantcms-couchrest_model-0.2.4 vendor/rails/activesupport/lib/active_support/core_ext/blank.rb
radiantcms-couchrest_model-0.2.2 vendor/rails/activesupport/lib/active_support/core_ext/blank.rb
radiantcms-couchrest_model-0.2.1 vendor/rails/activesupport/lib/active_support/core_ext/blank.rb
radiantcms-couchrest_model-0.2 vendor/rails/activesupport/lib/active_support/core_ext/blank.rb
radiantcms-couchrest_model-0.1.9 vendor/rails/activesupport/lib/active_support/core_ext/blank.rb
radiantcms-couchrest_model-0.1.8 vendor/rails/activesupport/lib/active_support/core_ext/blank.rb
radiantcms-couchrest_model-0.1.7 vendor/rails/activesupport/lib/active_support/core_ext/blank.rb
radiantcms-couchrest_model-0.1.6 vendor/rails/activesupport/lib/active_support/core_ext/blank.rb
radiantcms-couchrest_model-0.1.5 vendor/rails/activesupport/lib/active_support/core_ext/blank.rb
nbudin-castronaut-0.7.5 vendor/activesupport/lib/active_support/core_ext/blank.rb
radiant-0.8.2 vendor/rails/activesupport/lib/active_support/core_ext/blank.rb
usher-0.7.0 spec/rails2_3/vendor/rails/vendor/rails/activesupport/pkg/activesupport-2.3.3/lib/active_support/core_ext/blank.rb
usher-0.7.0 spec/rails2_3/vendor/rails/vendor/rails/activesupport/lib/active_support/core_ext/blank.rb
usher-0.7.0 spec/rails2_2/vendor/rails/vendor/rails/activesupport/pkg/activesupport-2.2.2/lib/active_support/core_ext/blank.rb