4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/dr/base/bool.rb', line 4
def to_bool(el, default=nil)
case el
when String
string=el.chomp
return true if string =~ (/(true|t|yes|y|1)$/i)
return false if string.empty? || string =~ (/(false|f|no|n|0)$/i)
when Fixnum
return ! (el == 0)
when Process::Status
exitstatus=el.exitstatus
return exitstatus == 0
else
return true if el == true
return false if el == false
end
return default unless default.nil?
raise ArgumentError.new("Invalid value for Boolean: \"#{el}\"")
end
|