Module: InternetConnection

Defined in:
lib/internet_connection.rb

Class Method Summary collapse

Class Method Details

.off?Boolean

exactly the opposite of on?

Returns:

  • (Boolean)


26
27
28
# File 'lib/internet_connection.rb', line 26

def off?
  !on?
end

.on?Boolean

InternetConnection#on? will try to resolve google.com dns. if it can you’ve got an internet connection

Returns:

  • (Boolean)


17
18
19
20
21
22
23
# File 'lib/internet_connection.rb', line 17

def on?
  begin
    !!Resolv.getaddress('www.google.com')
  rescue Errno::EHOSTUNREACH
    return false
  end
end