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#setuid?

() -> bool
setuid? → true or false

Returns whether the setuid bit is set in the special bits for the entry represented in self:

Example
path = '/tmp/t.tmp'
File.write(path, 'foo')
stat = File.stat(path)   # Take snapshot; bit not set.
stat.setuid?             # => false
stat.mode.to_s(8)        # => "100664"
File.chmod(0o4644, path) # Set the bit; snapshot not updated.
stat.setuid?             # => false
stat.mode.to_s(8)        # => "100664"
stat = File.stat(path)   # Fresh snapshot.
stat.setuid?             # => true
stat.mode.to_s(8)        # => "104644"
File.delete(path)        # Clean up.

On Windows, the bit is never set; the method always returns false.

See also #setgid? #size #readable_real? #size? also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0