I'm not sure how best to do this:
I've got a function that looks up an IP and returns the country it's from.
country = Geolix.lookup(remote_ip).country.registered_country.name
Sometimes it fails, and in that case, none of the array keys are defined.
In other languages, I might do something like:
try do
country = Geolix.lookup(remote_ip).country.registered_country.name
rescue
country = nil
end
I'm really struggling to get the syntax right. This also doesn't feel very 'clean'; is there a better way?