Sha256: 6bea958d44ff7cc9f0fe8b29ee0799847ca504e36934a2462d0362afdc5119d3

Contents?: true

Size: 442 Bytes

Versions: 2

Compression:

Stored size: 442 Bytes

Contents

class String
  # 0x3000: fullwidth whitespace
  NON_WHITESPACE_REGEXP = %r![^\s#{[0x3000].pack("U")}]!

  # A string is blank if it's empty or contains whitespaces only:
  #
  #   "".blank?                 # => true
  #   "   ".blank?              # => true
  #   " ".blank?               # => true
  #   " something here ".blank? # => false
  #
  def blank?
    self !~ NON_WHITESPACE_REGEXP
  end
  
  def present?
    !blank?
  end  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
clieop-1.0.1 lib/core_ext/string.rb
clieop-1.0.0 lib/core_ext/string.rb