Sha256: 50c7d746d1911a4fcdc2b8d9611d116a3dd952f8e6439df03c04a8d24835f8b7

Contents?: true

Size: 724 Bytes

Versions: 25

Compression:

Stored size: 724 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
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

25 entries across 25 versions & 7 rubygems

Version Path
3mix-castronaut-0.5.0.2 vendor/activesupport/lib/active_support/core_ext/blank.rb
masover-castronaut-0.4.4.4 vendor/activesupport/lib/active_support/core_ext/blank.rb
masover-castronaut-0.4.4.5 vendor/activesupport/lib/active_support/core_ext/blank.rb
masover-castronaut-0.5.0.1 vendor/activesupport/lib/active_support/core_ext/blank.rb
relevance-castronaut-0.4.1 vendor/activesupport/lib/active_support/core_ext/blank.rb
relevance-castronaut-0.4.2 vendor/activesupport/lib/active_support/core_ext/blank.rb
relevance-castronaut-0.4.3 vendor/activesupport/lib/active_support/core_ext/blank.rb
relevance-castronaut-0.4.4 vendor/activesupport/lib/active_support/core_ext/blank.rb
relevance-castronaut-0.4.5 vendor/activesupport/lib/active_support/core_ext/blank.rb
relevance-castronaut-0.4.6 vendor/activesupport/lib/active_support/core_ext/blank.rb
relevance-castronaut-0.5.0 vendor/activesupport/lib/active_support/core_ext/blank.rb
relevance-castronaut-0.5.1 vendor/activesupport/lib/active_support/core_ext/blank.rb
relevance-castronaut-0.5.2 vendor/activesupport/lib/active_support/core_ext/blank.rb
relevance-castronaut-0.5.3 vendor/activesupport/lib/active_support/core_ext/blank.rb
relevance-castronaut-0.5.4 vendor/activesupport/lib/active_support/core_ext/blank.rb
radiant-0.7.2 vendor/rails/activesupport/lib/active_support/core_ext/blank.rb
vibes-bj-1.2.2 spec/rails_root/vendor/rails/activesupport/lib/active_support/core_ext/blank.rb
vibes-bj-1.2.1 spec/rails_root/vendor/rails/activesupport/lib/active_support/core_ext/blank.rb
activesupport-2.1.0 lib/active_support/core_ext/blank.rb
activesupport-2.1.2 lib/active_support/core_ext/blank.rb