Class: String

Inherits:
Object show all
Defined in:
lib/reactive_support/core_ext/object/blank.rb

Overview

Ruby’s core String class. See documentation for version 2.1.3, 2.0.0, or 1.9.3.

Instance Method Summary collapse

Instance Method Details

#blank?Boolean

When called on a string, the #blank? method returns true if the string is empty or consists only of whitespace:

''.blank?      # => true 
" \n ".blank?  # => true 
'foo'.blank?   # => false

Returns:

  • (Boolean)


18
19
20
# File 'lib/reactive_support/core_ext/object/blank.rb', line 18

def blank?
  !!(/\A[[:space:]]*\z/ =~ self) || self.empty?
end

#present?Boolean

When called on a string, the #present? method returns true unless the string is empty or consists only of whitespace:

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

Returns:

  • (Boolean)


28
29
30
# File 'lib/reactive_support/core_ext/object/blank.rb', line 28

def present?
  !blank?
end