📜  ruby raise argumenterror - Ruby 代码示例

📅  最后修改于: 2022-03-11 15:04:46.529000             🧑  作者: Mango

代码示例1
# raise ArgumentError, 'Put error message here' unless some_condition
# example from source link

def inverse(x)  
  raise ArgumentError, 'Argument is not numeric' unless x.is_a? Numeric  
  1.0 / x  
end  

puts inverse(2) # 0.5
puts inverse('not a number') # ArgumentError