Answers for "raise argumenterror ruby"

0

ruby raise argumenterror

# 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
Posted by: Guest on July-30-2021

Browse Popular Code Answers by Language