Skip to content

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

instance method

File::Stat#socket?

() -> bool
socket? → true or false

Returns whether entry in self is a socket:

Example
sock_path = '/tmp/socket'
server = UNIXServer.new(sock_path)
stat = File.stat(sock_path)
stat.socket?           # => true
File.delete(sock_path) # Clean up.
stat.socket?           # => true
file_path = '/etc/passwd'
File.exist?(file_path) # => true  # Snapshot not updated.
stat = File.stat(file_path)
stat.socket?           # => false
See also #size? #sticky? #size #symlink? also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0