# # people use ruby's "Integer()" method to cast an argument to a Fixnum all the # time because it raises errors on invalid input # Integer('42.0') #=> 42 Integer('foobar') #=> ArgumentError: invalid value for Integer: "foobar" # # it is crap however. have fun debugging this code run as root # # # returns true if pid is running, false otherwise # def alive pid pid = Integer("#{ pid }") begin Process::kill(0, pid) true rescue Errno::ESRCH false end end alive(pid = nil) # # this is because # Integer(nil) #=> 0 # # and killing process 0 is BAAAAAAAAD # # # it also violates POLS since Float(nil) raises an error... # # the moral is, use: # int = Float(arg).to_i # # when you want to both validate and cast to an int #