Module: InternetConnection

Defined in:
lib/internet_connection.rb

Class Method Summary collapse

Class Method Details

.off?Boolean

exactly the opposite of on?

Returns:

  • (Boolean)


24
25
26
# File 'lib/internet_connection.rb', line 24

def off?
  !on?
end

.on?(host = 'www.example.com') ⇒ Boolean

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

Returns:

  • (Boolean)


15
16
17
18
19
20
21
# File 'lib/internet_connection.rb', line 15

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