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
file.c
View on GitHub ↗
static VALUE
rb_stat_S(VALUE obj)
{
#ifdef S_ISSOCK
if (S_ISSOCK(get_stat(obj)->ST_(mode))) return Qtrue;
#endif
return Qfalse;
}
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