Class: String

Inherits:
Object show all
Defined in:
lib/ext/object.rb

Direct Known Subclasses

Phrase::Delegate::Base

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)


111
112
113
114
115
116
117
118
# File 'lib/ext/object.rb', line 111

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)


92
93
94
# File 'lib/ext/object.rb', line 92

def encoding_aware?
  true
end