Sha256: 78fb8585010d260cfc478e2bf81b19a9ba720a37b99efa8a8a19686f6fd0b8ec

Contents?: true

Size: 1.44 KB

Versions: 30

Compression:

Stored size: 1.44 KB

Contents

# Vendored from activesupport 3.0.1
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

  # Returns object if it's #present? otherwise returns nil.
  # object.presence is equivalent to object.present? ? object : nil.
  #
  # This is handy for any representation of objects where blank is the same
  # as not present at all.  For example, this simplifies a common check for
  # HTTP POST/query parameters:
  #
  #   state   = params[:state]   if params[:state].present?
  #   country = params[:country] if params[:country].present?
  #   region  = state || country || 'US'
  #
  # ...becomes:
  #
  #   region = params[:state].presence || params[:country].presence || 'US'
  def presence
    self if present?
  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

30 entries across 30 versions & 4 rubygems

Version Path
jenkins-maestrodev-0.6.9 lib/jenkins/core_ext/object/blank.rb
jenkins-0.6.8 lib/jenkins/core_ext/object/blank.rb
jenkins-0.6.6 lib/jenkins/core_ext/object/blank.rb
jenkins-0.6.5 lib/jenkins/core_ext/object/blank.rb
akqa-jenkins-0.6.4.1 lib/jenkins/core_ext/object/blank.rb
jenkins-0.6.4 lib/jenkins/core_ext/object/blank.rb
jenkins-0.6.3 lib/jenkins/core_ext/object/blank.rb
jenkins-0.6.2 lib/jenkins/core_ext/object/blank.rb
jenkins-0.6.1 lib/jenkins/core_ext/object/blank.rb
jenkins-0.6.0 lib/jenkins/core_ext/object/blank.rb
hudson-0.5.0 lib/hudson/core_ext/object/blank.rb
hudson-0.3.1 lib/hudson/core_ext/object/blank.rb
hudson-0.3.0 lib/hudson/core_ext/object/blank.rb
hudson-0.3.0.beta.19 lib/hudson/core_ext/object/blank.rb
hudson-0.3.0.beta.18 lib/hudson/core_ext/object/blank.rb
hudson-0.3.0.beta.17 lib/hudson/core_ext/object/blank.rb
hudson-0.3.0.beta.16 lib/hudson/core_ext/object/blank.rb
hudson-0.3.0.beta.15 lib/hudson/core_ext/object/blank.rb
hudson-0.3.0.beta.14 lib/hudson/core_ext/object/blank.rb
hudson-0.3.0.beta.13 lib/hudson/core_ext/object/blank.rb