Class: String

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

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)


41
42
43
# File 'lib/reactive_support/core_ext/object/blank.rb', line 41

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)


51
52
53
# File 'lib/reactive_support/core_ext/object/blank.rb', line 51

def present?
  !blank?
end