Class: Gastly::Utils::String
- Inherits:
-
Object
- Object
- Gastly::Utils::String
- Defined in:
- lib/gastly/utils/string.rb
Constant Summary collapse
- BLANK_RE =
/\A[[:space:]]*\z/
Instance Attribute Summary collapse
-
#string ⇒ Object
readonly
Returns the value of attribute string.
Instance Method Summary collapse
-
#blank? ⇒ true, false
A string is blank if it’s empty or contains whitespaces only:.
-
#initialize(string = '') ⇒ String
constructor
A new instance of String.
-
#present? ⇒ true, false
An object is present if it’s not blank.
Constructor Details
#initialize(string = '') ⇒ String
Returns a new instance of String.
8 9 10 |
# File 'lib/gastly/utils/string.rb', line 8 def initialize(string = '') @string = string.to_s end |
Instance Attribute Details
#string ⇒ Object (readonly)
Returns the value of attribute string.
6 7 8 |
# File 'lib/gastly/utils/string.rb', line 6 def string @string end |
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
24 25 26 |
# File 'lib/gastly/utils/string.rb', line 24 def blank? BLANK_RE === string end |
#present? ⇒ true, false
An object is present if it’s not blank.
31 32 33 |
# File 'lib/gastly/utils/string.rb', line 31 def present? !blank? end |