class File
Public Class Methods
umask() → int
click to toggle source
umask( int) → int
umask( int) { ... } → obj
Returns the current umask value for this process. If the optional argument is given, set the umask to that value and return the previous value. If a block is given, the umask value will be reset and the blocks value is returned.
Umask values are subtracted from the default permissions, so a
umask of 0222
would make a file read-only for everyone.
File.umask( 0006) #=> 18 File.umask #=> 6
VALUE rb_file_s_umask( int argc, VALUE *argv) { int omask = 0; rb_secure( 2); switch (argc) { case 0: omask = umask( 0777); umask( omask); break; case 1: omask = umask( NUM2INT( argv[ 0])); if (rb_block_given_p()) return rb_ensure( rb_yield, Qnil, supplement_do_unumask, INT2FIX( omask)); break; default: rb_raise( rb_eArgError, "wrong number of arguments (%d for 0..1)", argc); } return INT2FIX( omask); }
Public Instance Methods
size → integer
click to toggle source
Returns file
's size. A shortcut for
file.stat.size
. This constitutes consistency with
StringIO
.
file.size #=> 16384
VALUE rb_file_size( VALUE obj) { #ifdef HAVE_HEADER_RUBY_H OpenFile *fptr; #else rb_io_t *fptr; #endif struct stat st; GetOpenFile( obj, fptr); #ifdef HAVE_HEADER_RUBY_H if (fstat( fileno( fptr->f), &st) == -1) { rb_sys_fail( fptr->path); } #else if (fstat( fptr->fd, &st) == -1) { rb_sys_fail_str( fptr->pathv); } #endif return INT2FIX( st.st_size); }