Sha256: 28127fb283280a88a7315f451b127d7ceb770401d48a67467c58e89b61955769

Contents?: true

Size: 906 Bytes

Versions: 13

Compression:

Stored size: 906 Bytes

Contents

class Object  #:nodoc:all
  # 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?
  #:nodoc
  def blank?
    respond_to?(:empty?) ? empty? : !self
  end

  # An object is present if it's not blank.
   #:nodoc
  def present?
    !blank?
  end
end

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

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

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

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

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

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

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

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
davidlee-state-fu-0.10.0 lib/state_fu/active_support_lite/blank.rb
davidlee-state-fu-0.11.0 lib/state_fu/active_support_lite/blank.rb
davidlee-state-fu-0.11.1 lib/support/active_support_lite/blank.rb
davidlee-state-fu-0.12.0 lib/support/active_support_lite/blank.rb
davidlee-state-fu-0.12.1 lib/support/active_support_lite/blank.rb
state-fu-0.13.5 lib/support/active_support_lite/blank.rb
state-fu-0.13.4 lib/support/active_support_lite/blank.rb
state-fu-0.13.3 lib/support/active_support_lite/blank.rb
state-fu-0.13.1 lib/support/active_support_lite/blank.rb
state-fu-0.13.0 lib/support/active_support_lite/blank.rb
state-fu-0.12.3 lib/support/active_support_lite/blank.rb
state-fu-0.12.1 lib/support/active_support_lite/blank.rb
state-fu-0.11.1 lib/support/active_support_lite/blank.rb