Class: Integer

Inherits:
Object
  • Object
show all
Defined in:
lib/safebool.rb

Instance Method Summary collapse

Instance Method Details

#parse_boolObject



165
166
167
168
169
170
171
172
173
# File 'lib/safebool.rb', line 165

def parse_bool
  if self == 0
    false
  elsif self == 1
    true
  else
    nil  ## note: returns nil if can't convert to true or false
  end
end

#to_bObject



160
161
162
163
164
# File 'lib/safebool.rb', line 160

def to_b
  value = parse_bool()
  value = true  if value.nil?   ## note return true for all undefined / unknown number/numeric values that cannot convert to bool
  value
end