Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Pathname#ftype
() -> ::String
ftype → string
pathname_builtin.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/pathname_builtin.rb, line 1709
def ftype() File.ftype(@path) end
Returns the string type of the object at the path in self, one of:
-
'file'. -
'directory'. -
'characterSpecial'. -
'blockSpecial'. -
'fifo'. -
'link'. -
'socket'.
Examples:
Example
Pathname('/etc/passwd').ftype # => "file" Pathname('/etc').ftype # => "directory" Pathname('/dev/null').ftype # => "characterSpecial" Pathname('/dev/loop0').ftype # => "blockSpecial" File.mkfifo('/tmp/pipe', 0o666) Pathname('/tmp/pipe').ftype # => "fifo" File.symlink('/etc/passwd', '/tmp/link') Pathname('/tmp/link').ftype # => "link" require 'socket' UNIXServer.new('/tmp/socket') Pathname('/tmp/socket').ftype # => "socket" File.delete('/tmp/link', '/tmp/pipe', '/tmp/socket') # Clean up.
Returns 'unknown' if the type cannot be determined.