Working in Rails 4.2 and Ruby 2.3.3
I'm dealing with an API that has an error fiend in certain circumstances but not in other circumstances. I would like to check to see if that error key exists and, if yes, downcase it and search for the existence of something. Like this where parsed is a hash:
# parsed could be either:
# {error: "Email does not exist"}
# or
# {result: ... }
return true if parsed.dig('error').downcase!.include?('email does not exist') # refactor
I can see dig returns nil in this case. Is there any way I can tell that if statement to exit if nil? Maybe force it to false and exit without adding a lot of ceremony code?
I know I could do something like this but it seems cumbersome:
unless parsed['error'].nil?
return true if parsed.dig('error').downcase!.include?('email does not exist') # refactor
end