Checking for internet connection [duplicate]
How to check for internet connection using Ruby.
You could try using Net::HTTP and 'pinging' a reliable URL such as Google and check for an exception indicating they do not have an internet connection.
Using Ping
is deprecated in Ruby 1.9.x as explained here: https://stackoverflow.com/a/8317838
A more future-proof, as well as more code-relevant solution would be the solution given by that answer, using open-uri
and returning false on exception.
精彩评论