Skip to content

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

instance method

Pathname#socket?

() -> untyped
socket? → true or false

Returns whether entry at the path in self is a socket:

Example
require 'socket'
sock_path = '/tmp/socket'
sock_pn = Pathname(sock_path)
sock_pn.exist?  # => false
sock_pn.socket? # => false
server = UNIXServer.new(sock_path)
sock_pn.exist?  # => true
sock_pn.socket? # => true
# Clean up.
server.close
sock_pn.delete
file_path = '/etc/passwd'
file_pn = Pathname(file_path)
file_pn.file?   # => true
file_pn.socket? # => false

Returns false on Windows.

See also #size? #split #size #split_names also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0