Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
FileTest#world_writable?
(::path | ::io file_name) -> ::Integer?
File.world_writable?(object) → integer or nil
file.c
View on GitHub ↗
static VALUE
rb_file_world_writable_p(VALUE obj, VALUE fname)
{
#ifdef S_IWOTH
struct stat st;
if (rb_stat(fname, &st) < 0) return Qnil;
if ((st.st_mode & (S_IWOTH)) == S_IWOTH) {
return UINT2NUM(st.st_mode & (S_IRUGO|S_IWUGO|S_IXUGO));
}
#endif
return Qnil;
}
If the given object exists and is writable by others, returns the integer permissions for the entry; otherwise, returns nil:
Example
filepath = '/tmp/t.tmp' File.world_writable?(filepath) # => nil # Non-existent. File.write(filepath, 'foo') # Create file. File.world_writable?(filepath) # => nil # Not world-writable. File.chmod(0o777, filepath) # Make world-writable. File.world_writable?(filepath).to_s(8) # => "777" # World-writable. File.delete(filepath) # Clean up. File.world_writable?('/tmp').to_s(8) # => "777" # Directory. File.world_writable?($stdin) # => nil # IO object.
See also
#world_readable?
#writable?
#symlink?
#writable_real?
also in
4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0