Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
File::Stat#executable?
() -> bool
executable? → true or false
file.c
View on GitHub ↗
static VALUE
rb_stat_x(VALUE obj)
{
rb_io_stat_data *st = get_stat(obj);
#ifdef USE_GETEUID
if (geteuid() == 0) {
return RBOOL(st->ST_(mode) & S_IXUGO);
}
#endif
#ifdef S_IXUSR
if (rb_stat_owned(obj))
return RBOOL(st->ST_(mode) & S_IXUSR);
#endif
#ifdef S_IXGRP
if (rb_stat_grpowned(obj))
return RBOOL(st->ST_(mode) & S_IXGRP);
#endif
#ifdef S_IXOTH
if (!(st->ST_(mode) & S_IXOTH)) return Qfalse;
#endif
return Qtrue;
}
Returns whether the filesystem entry represented by self is executable by the effective owner/group of the current process:
Example
File.stat('/bin/ruby').executable? # => true File.stat('/etc').executable? # => true File.stat('/etc/passwd').executable? # => false
Raises Errno::ENOENT if the entry does not exist.
Note that some filesystem settings may cause this method to return true even though the entry is not executable by the effective owner/group.