Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/tap/formatters/core_ext/string.rb

Overview

Extensions to the core String class

Instance Method Summary collapse

Instance Method Details

#blank?Boolean

Checks whether a string is blank. A string is considered blank if it is either empty or contains only whitespaces.

Examples:

''.blank?
#=> true
'  '.blank?
#=> true
'  abc  '.blank?
#=> false

Returns:

  • (Boolean)

    true is the string is blank, false otherwise



22
23
24
# File 'lib/rspec/tap/formatters/core_ext/string.rb', line 22

def blank?
  empty? || strip.empty?
end

#present?Boolean

Checks whether a string is present. A string is considered present if it is not blank.

Examples:

''.present?
#=> false
'  '.present?
#=> false
'  abc  '.present?
#=> true

Returns:

  • (Boolean)

    true is the string is present, false otherwise



44
45
46
# File 'lib/rspec/tap/formatters/core_ext/string.rb', line 44

def present?
  !blank?
end