G
Garance A Drosehn
I wanted to use Socket.gethostname to get the current hostname
without executing a unix command. So:
require 'socket'
$this_host = Socket.gethostname
I have to run this code on several platforms, and it turned out that
some of them do not have 'socket'. So, my first idea was change
it to:
begin
require 'socket'
$this_host = Socket.gethostname
rescue
$this_host = `hostname`.chomp
end
but the require still caused the script to terminate on the platforms
which didn't have 'socket'. I already have an alternate solution for
this specific case, but I'm wondering if there was something that I
missed. Is there any way to catch errors from a require command?
without executing a unix command. So:
require 'socket'
$this_host = Socket.gethostname
I have to run this code on several platforms, and it turned out that
some of them do not have 'socket'. So, my first idea was change
it to:
begin
require 'socket'
$this_host = Socket.gethostname
rescue
$this_host = `hostname`.chomp
end
but the require still caused the script to terminate on the platforms
which didn't have 'socket'. I already have an alternate solution for
this specific case, but I'm wondering if there was something that I
missed. Is there any way to catch errors from a require command?