Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

class method

Socket.gethostname

() -> ::String
Socket.gethostname => hostname

Returns the hostname.

Example
p Socket.gethostname #=> "hal"

Note that it is not guaranteed to be able to convert to IP address using gethostbyname, getaddrinfo, etc. If you need local IP address, use Socket.ip_address_list.