Method: Object#to_bool

Defined in:
lib/extra/object.rb

#to_boolObject

Convert object to boolean.

Example:

"foo".to_bool #=> true

false.to_bool #=> false

nil.to_bool #=> nil

true.to_bool #=> true

Returns: Boolean or nil.



81
82
83
84
85
86
87
# File 'lib/extra/object.rb', line 81

def to_bool
  if [FalseClass, NilClass].include? self.class
    self
  else
    true
  end
end