Sha256: 6b26e369f0539cd4130383b05e849a5c68ef9fdad86d73a90cba0f6f3ac36eff

Contents?: true

Size: 815 Bytes

Versions: 49

Compression:

Stored size: 815 Bytes

Contents

class Object #:nodoc:
  # 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

49 entries across 49 versions & 14 rubygems

Version Path
adva-0.3.2 test/webrat/lib/webrat/core_extensions/blank.rb
adva-0.3.1 test/webrat/lib/webrat/core_extensions/blank.rb
adva-0.3.0 test/webrat/lib/webrat/core_extensions/blank.rb
adva-0.2.4 test/webrat/lib/webrat/core_extensions/blank.rb
adva-0.2.3 test/webrat/lib/webrat/core_extensions/blank.rb
adva-0.2.2 test/webrat/lib/webrat/core_extensions/blank.rb
adva-0.2.1 test/webrat/lib/webrat/core_extensions/blank.rb
adva-0.2.0 test/webrat/lib/webrat/core_extensions/blank.rb
adva-0.1.4 test/webrat/lib/webrat/core_extensions/blank.rb
adva-0.1.3 test/webrat/lib/webrat/core_extensions/blank.rb
adva-0.1.2 test/webrat/lib/webrat/core_extensions/blank.rb
adva-0.1.1 test/webrat/lib/webrat/core_extensions/blank.rb
adva-0.1.0 test/webrat/lib/webrat/core_extensions/blank.rb
adva-0.0.1 test/webrat/lib/webrat/core_extensions/blank.rb
aslakhellesoy-webrat-0.3.2.1 lib/webrat/core_extensions/blank.rb
aslakhellesoy-webrat-0.3.2.2 lib/webrat/core_extensions/blank.rb
auxesis-webrat-0.4.1 lib/webrat/core_extensions/blank.rb
benschwarz-webrat-0.3.2.1 lib/webrat/core_extensions/blank.rb
brynary-webrat-0.3.2.1 lib/webrat/core_extensions/blank.rb
brynary-webrat-0.3.2.2 lib/webrat/core_extensions/blank.rb