Sha256: 197886380449ef0fb755a3e28c73bca7987491349a0f74f224f020e849de446e

Contents?: true

Size: 802 Bytes

Versions: 15

Compression:

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

15 entries across 15 versions & 7 rubygems

Version Path
activesupport_csi-2.3.5.p8 lib/active_support/core_ext/object/blank.rb
activesupport_csi-2.3.5.p7 lib/active_support/core_ext/object/blank.rb
activesupport_csi-2.3.5.p6 lib/active_support/core_ext/object/blank.rb
webroar-0.5.0 src/admin_panel/vendor/rails/activesupport/lib/active_support/core_ext/object/blank.rb
webroar-0.4.0 src/admin_panel/vendor/rails/activesupport/lib/active_support/core_ext/object/blank.rb
cassandra_object-0.6.0.pre vendor/activesupport/lib/active_support/core_ext/object/blank.rb
radiant-0.9.0.rc2 vendor/rails/activesupport/lib/active_support/core_ext/object/blank.rb
webroar-0.3.1 src/admin_panel/vendor/rails/activesupport/lib/active_support/core_ext/object/blank.rb
webroar-0.3.0 src/admin_panel/vendor/rails/activesupport/lib/active_support/core_ext/object/blank.rb
activesupport-2.3.6.pre lib/active_support/core_ext/object/blank.rb
simply_stated-0.0.5 vendor/gems/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/object/blank.rb
simply_stated-0.0.4 vendor/gems/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/object/blank.rb
activesupport-2.3.5 lib/active_support/core_ext/object/blank.rb
activesupport-3.0.pre lib/active_support/core_ext/object/blank.rb
recliner-0.0.1 vendor/activesupport/lib/active_support/core_ext/object/blank.rb