Skip to content

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

instance method

FileTest#owned?

(::path | ::io file_name) -> bool
File.owned?(object) → true or false

Returns whether the given object represents a filesystem entry or IO object that exists and is owned by the user of the current process:

Example
filepath = 'doc/t.tmp'
File.write(filepath, 'foo')
File.owned?(filepath) # => true
File.delete(filepath) # Clean up.
dirpath = 'doc/tmp'
Dir.mkdir(dirpath)
File.owned?(dirpath)  # => true
Dir.rmdir(dirpath)    # Clean up.
File.owned?($stdin)   # => true
File.owned?('/etc')   # => false
See also #identical? #pipe? #grpowned? #readable? also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0