Class: String

Inherits:
Object show all
Defined in:
lib/tagged_logging/blank_ext.rb

Constant Summary collapse

NON_WHITESPACE_REGEXP =

0x3000: fullwidth whitespace

%r![^\s#{[0x3000].pack("U")}]!

Instance Method Summary collapse

Instance Method Details

#blank?Boolean

A string is blank if it’s empty or contains whitespaces only:

"".blank?                 # => true
"   ".blank?              # => true
" ".blank?               # => true
" something here ".blank? # => false

Returns:

  • (Boolean)


98
99
100
101
102
103
104
105
# File 'lib/tagged_logging/blank_ext.rb', line 98

def blank?
  # 1.8 does not takes [:space:] properly
  if encoding_aware?
    self !~ /[^[:space:]]/
  else
    self !~ NON_WHITESPACE_REGEXP
  end
end

#encoding_aware?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/tagged_logging/blank_ext.rb', line 80

def encoding_aware?
  true
end