7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/lucid_works/utils.rb', line 7
def to_bool(thing)
if thing.kind_of?(TrueClass) || thing.kind_of?(FalseClass)
thing
elsif thing.kind_of?(String)
raise "Sorry, I can't to_bool \"#{thing}\"" unless (TRUE_VALUES + FALSE_VALUES).include?(thing.downcase)
TRUE_VALUES.include?(thing.downcase)
elsif thing.kind_of?(Integer)
raise "Sorry, I can't to_bool #{thing}" unless [0, 1].include?(thing)
thing == 1
else
raise "Sorry, I can't to_bool things of class #{thing.class.name}"
end
end
|