Class: String
- Defined in:
- lib/fir/patches/native_patch.rb,
lib/fir/patches/native_patch.rb
Constant Summary collapse
- BLANK_RE =
/\A[[:space:]]*\z/
Instance Method Summary collapse
-
#blank? ⇒ true, false
A string is blank if it’s empty or contains whitespaces only:.
-
#to_utf8 ⇒ Object
Convert String encoding to UTF-8.
Instance Method Details
#blank? ⇒ true, false
A string is blank if it’s empty or contains whitespaces only:
''.blank? # => true
' '.blank? # => true
"\t\n\r".blank? # => true
' blah '.blank? # => false
Unicode whitespace is supported:
"\u00a0".blank? # => true
116 117 118 |
# File 'lib/fir/patches/native_patch.rb', line 116 def blank? BLANK_RE === self end |
#to_utf8 ⇒ Object
Convert String encoding to UTF-8
223 224 225 |
# File 'lib/fir/patches/native_patch.rb', line 223 def to_utf8 encode(Encoding.find('UTF-8'), invalid: :replace, undef: :replace, replace: '') end |