Class: Gastly::Utils::String

Inherits:
Object
  • Object
show all
Defined in:
lib/gastly/utils/string.rb

Constant Summary collapse

BLANK_RE =
/\A[[:space:]]*\z/

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#stringObject (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

Returns:

  • (true, false)


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.

Returns:

  • (true, false)


31
32
33
# File 'lib/gastly/utils/string.rb', line 31

def present?
  !blank?
end