file.chmod(mode_int) → 0
Changes permission bits on file to the bit pattern represented by mode_int. Actual effects are platform dependent; on Unix systems, see chmod(2) for details. Follows symbolic links. Also see File#lchmod.
f = File.new("out", "w"); f.chmod(0644) #=> 0
Source Code
/* * call-seq: * file.chmod(mode_int) => 0 * * Changes permission bits on <i>file</i> to the bit pattern * represented by <i>mode_int</i>. Actual effects are platform * dependent; on Unix systems, see <code>chmod(2)</code> for details. * Follows symbolic links. Also see <code>File#lchmod</code>. * * f = File.new("out", "w"); * f.chmod(0644) #=> 0 */ static VALUE rb_file_chmod(obj, vmode) VALUE obj, vmode; { OpenFile *fptr; int mode; rb_secure(2); mode = NUM2INT(vmode); GetOpenFile(obj, fptr); #ifdef HAVE_FCHMOD if (fchmod(fileno(fptr->f), mode) == -1) rb_sys_fail(fptr->path); #else if (!fptr->path) return Qnil; if (chmod(fptr->path, mode) == -1) rb_sys_fail(fptr->path); #endif return INT2FIX(0); }
<code/>and<pre/>for code samples.