The parent class for all constructed encodings. The value attribute of a Constructive
is always an Array
. Attributes are the same as for ASN1Data
, with the addition of tagging.
Most constructed encodings come in the form of a SET or a SEQUENCE. These encodings are represented by one of the two sub-classes of Constructive:
OpenSSL::ASN1::Sequence
Please note that tagged sequences and sets are still parsed as instances of ASN1Data
. Find
further details on tagged values there.
int = OpenSSL::ASN1::Integer.new(1) str = OpenSSL::ASN1::PrintableString.new('abc') sequence = OpenSSL::ASN1::Sequence.new( [ int, str ] )
int = OpenSSL::ASN1::Integer.new(1) str = OpenSSL::ASN1::PrintableString.new('abc') set = OpenSSL::ASN1::Set.new( [ int, str ] )
Raised when the buffer cannot be allocated for some reason, or you try to use a buffer that’s not allocated.
Class for representing HTTP method OPTIONS:
require 'net/http' uri = URI('http://example.com') hostname = uri.hostname # => "example.com" req = Net::HTTP::Options.new(uri) # => #<Net::HTTP::Options OPTIONS> res = Net::HTTP.start(hostname) do |http| http.request(req) end
See Request Headers.
Properties:
Request body: optional.
Response body: yes.
Safe: yes.
Idempotent: yes.
Cacheable: no.
Related:
Net::HTTP#options
: sends OPTIONS
request, returns response object.
Switch
that can omit argument.
Raised when the query given to a pattern is either invalid Ruby syntax or is using syntax that we don’t yet support.
A location field represents the location of some part of the node in the source code. For example, the location of a keyword or an operator. It resolves to a Prism::Location
in Ruby.
Represents a specification retrieved via the rubygems.org API.
This is used to avoid loading the full Specification object when all we need is the name, version, and dependencies.
A GitSpecification
represents a gem that is sourced from a git repository and is being loaded through a gem dependencies file through the git:
option.
Represents a possible Specification object returned from IndexSet. Used to delay needed to download full Specification objects when only the name
and version
are needed.
A LocalSpecification
comes from a .gem file on the local filesystem.
The LockSpecification
comes from a lockfile (Gem::RequestSet::Lockfile
).
A LockSpecification’s dependency information is pre-filled from the lockfile.
The Resolver::SpecSpecification contains common functionality for Resolver specifications that are backed by a Gem::Specification
.
A Resolver::Specification contains a subset of the information contained in a Gem::Specification
. Only the information necessary for dependency resolution in the resolver is included.
A VendorSpecification
represents a gem that has been unpacked into a project and is being loaded through a gem dependencies file through the path:
option.
Gem::Security
default exception type
An object representation of a stack frame, initialized by Kernel#caller_locations
.
For example:
# caller_locations.rb def a(skip) caller_locations(skip) end def b(skip) a(skip) end def c(skip) b(skip) end c(0..2).map do |call| puts call.to_s end
Running ruby caller_locations.rb
will produce:
caller_locations.rb:2:in `a' caller_locations.rb:5:in `b' caller_locations.rb:8:in `c'
Here’s another example with a slightly different result:
# foo.rb class Foo attr_accessor :locations def initialize(skip) @locations = caller_locations(skip) end end Foo.new(0..2).locations.map do |call| puts call.to_s end
Now run ruby foo.rb
and you should see:
init.rb:4:in `initialize' init.rb:8:in `new' init.rb:8:in `<main>'
Represents an expression modified with a rescue.
foo rescue nil ^^^^^^^^^^^^^^
This is not an existing class, but documentation of the interface that Scheduler
object should comply to in order to be used as argument to Fiber.scheduler
and handle non-blocking fibers. See also the “Non-blocking fibers” section in Fiber
class docs for explanations of some concepts.
Scheduler’s behavior and usage are expected to be as follows:
When the execution in the non-blocking Fiber
reaches some blocking operation (like sleep, wait for a process, or a non-ready I/O), it calls some of the scheduler’s hook methods, listed below.
Scheduler
somehow registers what the current fiber is waiting on, and yields control to other fibers with Fiber.yield
(so the fiber would be suspended while expecting its wait to end, and other fibers in the same thread can perform)
At the end of the current thread execution, the scheduler’s method scheduler_close is called
The scheduler runs into a wait loop, checking all the blocked fibers (which it has registered on hook calls) and resuming them when the awaited resource is ready (e.g. I/O ready or sleep time elapsed).
This way concurrent execution will be achieved transparently for every individual Fiber’s code.
Scheduler
implementations are provided by gems, like Async.
Hook methods are:
io_wait
, io_read
, io_write
, io_pread
, io_pwrite
, and io_select
, io_close
(the list is expanded as Ruby developers make more methods having non-blocking calls)
When not specified otherwise, the hook implementations are mandatory: if they are not implemented, the methods trying to call hook will fail. To provide backward compatibility, in the future hooks will be optional (if they are not implemented, due to the scheduler being created for the older Ruby version, the code which needs this hook will not fail, and will just behave in a blocking fashion).
It is also strongly recommended that the scheduler implements the fiber
method, which is delegated to by Fiber.schedule
.
Sample toy implementation of the scheduler can be found in Ruby’s code, in test/fiber/scheduler.rb
A Complex object houses a pair of values, given when the object is created as either rectangular coordinates or polar coordinates.
The rectangular coordinates of a complex number are called the real and imaginary parts; see Complex number definition.
You can create a Complex object from rectangular coordinates with:
A complex literal.
Method Complex.rect
.
Method Kernel#Complex
, either with numeric arguments or with certain string arguments.
Method String#to_c
, for certain strings.
Note that each of the stored parts may be a an instance one of the classes Complex
, Float
, Integer
, or Rational
; they may be retrieved:
Separately, with methods Complex#real
and Complex#imaginary
.
Together, with method Complex#rect
.
The corresponding (computed) polar values may be retrieved:
Separately, with methods Complex#abs
and Complex#arg
.
Together, with method Complex#polar
.
The polar coordinates of a complex number are called the absolute and argument parts; see Complex polar plane.
In this class, the argument part in expressed radians (not degrees).
You can create a Complex object from polar coordinates with:
Method Complex.polar
.
Method Kernel#Complex
, with certain string arguments.
Method String#to_c
, for certain strings.
Note that each of the stored parts may be a an instance one of the classes Complex
, Float
, Integer
, or Rational
; they may be retrieved:
Separately, with methods Complex#abs
and Complex#arg
.
Together, with method Complex#polar
.
The corresponding (computed) rectangular values may be retrieved:
Separately, with methods Complex#real
and Complex#imag
.
Together, with method Complex#rect
.
First, what’s elsewhere:
Class Complex inherits (directly or indirectly) from classes Numeric and Object.
Includes (indirectly) module Comparable.
Here, class Complex has methods for:
::polar
: Returns a new Complex object based on given polar coordinates.
::rect
(and its alias ::rectangular
): Returns a new Complex object based on given rectangular coordinates.
abs
(and its alias magnitude
): Returns the absolute value for self
.
arg
(and its aliases angle
and phase
): Returns the argument (angle) for self
in radians.
denominator
: Returns the denominator of self
.
finite?
: Returns whether both self.real
and self.image
are finite.
hash
: Returns the integer hash value for self
.
imag
(and its alias imaginary
): Returns the imaginary value for self
.
infinite?
: Returns whether self.real
or self.image
is infinite.
numerator
: Returns the numerator of self
.
polar
: Returns the array [self.abs, self.arg]
.
inspect
: Returns a string representation of self
.
real
: Returns the real value for self
.
real?
: Returns false
; for compatibility with Numeric#real?
.
rect
(and its alias rectangular
): Returns the array [self.real, self.imag]
.
<=>
: Returns whether self
is less than, equal to, or greater than the given argument.
==
: Returns whether self
is equal to the given argument.
rationalize
: Returns a Rational
object whose value is exactly or approximately equivalent to that of self.real
.
to_c
: Returns self
.
to_d: Returns the value as a BigDecimal
object.
to_f
: Returns the value of self.real
as a Float
, if possible.
to_i
: Returns the value of self.real
as an Integer
, if possible.
to_r
: Returns the value of self.real
as a Rational
, if possible.
to_s
: Returns a string representation of self
.
Complex
Arithmetic *
: Returns the product of self
and the given numeric.
**
: Returns self
raised to power of the given numeric.
+
: Returns the sum of self
and the given numeric.
-
: Returns the difference of self
and the given numeric.
-@
: Returns the negation of self
.
/
: Returns the quotient of self
and the given numeric.
abs2
: Returns square of the absolute value (magnitude) for self
.
conj
(and its alias conjugate
): Returns the conjugate of self
.
fdiv
: Returns Complex.rect(self.real/numeric, self.imag/numeric)
.
JSON
::json_create
: Returns a new Complex object, deserialized from the given serialized hash.
as_json
: Returns a serialized hash constructed from self
.
These methods are provided by the JSON gem. To make these methods available:
require 'json/add/complex'
A File object is a representation of a file in the underlying platform.
Class File extends module FileTest
, supporting such singleton methods as File.exist?
.
Many examples here use these variables:
# English text with newlines. text = <<~EOT First line Second line Fourth line Fifth line EOT # Russian text. russian = "\u{442 435 441 442}" # => "тест" # Binary data. data = "\u9990\u9991\u9992\u9993\u9994" # Text file. File.write('t.txt', text) # File with Russian text. File.write('t.rus', russian) # File with binary data. f = File.new('t.dat', 'wb:UTF-16') f.write(data) f.close
Methods File.new
and File.open
each create a File object for a given file path.
Methods File.new
and File.open
each may take string argument mode
, which:
Begins with a 1- or 2-character read/write mode.
May also contain a 1-character data mode.
May also contain a 1-character file-create mode.
The read/write mode
determines:
Whether the file is to be initially truncated.
Whether reading is allowed, and if so:
The initial read position in the file.
Where in the file reading can occur.
Whether writing is allowed, and if so:
The initial write position in the file.
Where in the file writing can occur.
These tables summarize:
Read/Write Modes for Existing File |------|-----------|----------|----------|----------|-----------| | R/W | Initial | | Initial | | Initial | | Mode | Truncate? | Read | Read Pos | Write | Write Pos | |------|-----------|----------|----------|----------|-----------| | 'r' | No | Anywhere | 0 | Error | - | | 'w' | Yes | Error | - | Anywhere | 0 | | 'a' | No | Error | - | End only | End | | 'r+' | No | Anywhere | 0 | Anywhere | 0 | | 'w+' | Yes | Anywhere | 0 | Anywhere | 0 | | 'a+' | No | Anywhere | End | End only | End | |------|-----------|----------|----------|----------|-----------| Read/Write Modes for \File To Be Created |------|----------|----------|----------|-----------| | R/W | | Initial | | Initial | | Mode | Read | Read Pos | Write | Write Pos | |------|----------|----------|----------|-----------| | 'w' | Error | - | Anywhere | 0 | | 'a' | Error | - | End only | 0 | | 'w+' | Anywhere | 0 | Anywhere | 0 | | 'a+' | Anywhere | 0 | End only | End | |------|----------|----------|----------|-----------|
Note that modes 'r'
and 'r+'
are not allowed for a non-existent file (exception raised).
In the tables:
Anywhere
means that methods IO#rewind
, IO#pos=
, and IO#seek
may be used to change the file’s position, so that allowed reading or writing may occur anywhere in the file.
End only
means that writing can occur only at end-of-file, and that methods IO#rewind
, IO#pos=
, and IO#seek
do not affect writing.
Error
means that an exception is raised if disallowed reading or writing is attempted.
'r'
:
File is not initially truncated:
f = File.new('t.txt') # => #<File:t.txt> f.size == 0 # => false
File’s initial read position is 0:
f.pos # => 0
File may be read anywhere; see IO#rewind
, IO#pos=
, IO#seek
:
f.readline # => "First line\n" f.readline # => "Second line\n" f.rewind f.readline # => "First line\n" f.pos = 1 f.readline # => "irst line\n" f.seek(1, :CUR) f.readline # => "econd line\n"
Writing is not allowed:
f.write('foo') # Raises IOError.
'w'
:
File is initially truncated:
path = 't.tmp' File.write(path, text) f = File.new(path, 'w') f.size == 0 # => true
File’s initial write position is 0:
f.pos # => 0
File may be written anywhere (even past end-of-file); see IO#rewind
, IO#pos=
, IO#seek
:
f.write('foo') f.flush File.read(path) # => "foo" f.pos # => 3 f.write('bar') f.flush File.read(path) # => "foobar" f.pos # => 6 f.rewind f.write('baz') f.flush File.read(path) # => "bazbar" f.pos # => 3 f.pos = 3 f.write('foo') f.flush File.read(path) # => "bazfoo" f.pos # => 6 f.seek(-3, :END) f.write('bam') f.flush File.read(path) # => "bazbam" f.pos # => 6 f.pos = 8 f.write('bah') # Zero padding as needed. f.flush File.read(path) # => "bazbam\u0000\u0000bah" f.pos # => 11
Reading is not allowed:
f.read # Raises IOError.
'a'
:
File is not initially truncated:
path = 't.tmp' File.write(path, 'foo') f = File.new(path, 'a') f.size == 0 # => false
File’s initial position is 0 (but is ignored):
f.pos # => 0
File may be written only at end-of-file; IO#rewind
, IO#pos=
, IO#seek
do not affect writing:
f.write('bar') f.flush File.read(path) # => "foobar" f.write('baz') f.flush File.read(path) # => "foobarbaz" f.rewind f.write('bat') f.flush File.read(path) # => "foobarbazbat"
Reading is not allowed:
f.read # Raises IOError.
'r+'
:
File is not initially truncated:
path = 't.tmp' File.write(path, text) f = File.new(path, 'r+') f.size == 0 # => false
File’s initial read position is 0:
f.pos # => 0
File may be read or written anywhere (even past end-of-file); see IO#rewind
, IO#pos=
, IO#seek
:
f.readline # => "First line\n" f.readline # => "Second line\n" f.rewind f.readline # => "First line\n" f.pos = 1 f.readline # => "irst line\n" f.seek(1, :CUR) f.readline # => "econd line\n" f.rewind f.write('WWW') f.flush File.read(path) # => "WWWst line\nSecond line\nFourth line\nFifth line\n" f.pos = 10 f.write('XXX') f.flush File.read(path) # => "WWWst lineXXXecond line\nFourth line\nFifth line\n" f.seek(-6, :END) # => 0 f.write('YYY') # => 3 f.flush # => #<File:t.tmp> File.read(path) # => "WWWst lineXXXecond line\nFourth line\nFifth YYYe\n" f.seek(2, :END) f.write('ZZZ') # Zero padding as needed. f.flush File.read(path) # => "WWWst lineXXXecond line\nFourth line\nFifth YYYe\n\u0000\u0000ZZZ"
'a+'
:
File is not initially truncated:
path = 't.tmp' File.write(path, 'foo') f = File.new(path, 'a+') f.size == 0 # => false
File’s initial read position is 0:
f.pos # => 0
File may be written only at end-of-file; IO#rewind
, IO#pos=
, IO#seek
do not affect writing:
f.write('bar') f.flush File.read(path) # => "foobar" f.write('baz') f.flush File.read(path) # => "foobarbaz" f.rewind f.write('bat') f.flush File.read(path) # => "foobarbazbat"
File may be read anywhere; see IO#rewind
, IO#pos=
, IO#seek
:
f.rewind f.read # => "foobarbazbat" f.pos = 3 f.read # => "barbazbat" f.seek(-3, :END) f.read # => "bat"
Note that modes 'r'
and 'r+'
are not allowed for a non-existent file (exception raised).
'w'
:
File’s initial write position is 0:
path = 't.tmp' FileUtils.rm_f(path) f = File.new(path, 'w') f.pos # => 0
File may be written anywhere (even past end-of-file); see IO#rewind
, IO#pos=
, IO#seek
:
f.write('foo') f.flush File.read(path) # => "foo" f.pos # => 3 f.write('bar') f.flush File.read(path) # => "foobar" f.pos # => 6 f.rewind f.write('baz') f.flush File.read(path) # => "bazbar" f.pos # => 3 f.pos = 3 f.write('foo') f.flush File.read(path) # => "bazfoo" f.pos # => 6 f.seek(-3, :END) f.write('bam') f.flush File.read(path) # => "bazbam" f.pos # => 6 f.pos = 8 f.write('bah') # Zero padding as needed. f.flush File.read(path) # => "bazbam\u0000\u0000bah" f.pos # => 11
Reading is not allowed:
f.read # Raises IOError.
'a'
:
File’s initial write position is 0:
path = 't.tmp' FileUtils.rm_f(path) f = File.new(path, 'a') f.pos # => 0
Writing occurs only at end-of-file:
f.write('foo') f.pos # => 3 f.write('bar') f.pos # => 6 f.flush File.read(path) # => "foobar" f.rewind f.write('baz') f.flush File.read(path) # => "foobarbaz"
Reading is not allowed:
f.read # Raises IOError.
'w+'
:
File’s initial position is 0:
path = 't.tmp' FileUtils.rm_f(path) f = File.new(path, 'w+') f.pos # => 0
File may be written anywhere (even past end-of-file); see IO#rewind
, IO#pos=
, IO#seek
:
f.write('foo') f.flush File.read(path) # => "foo" f.pos # => 3 f.write('bar') f.flush File.read(path) # => "foobar" f.pos # => 6 f.rewind f.write('baz') f.flush File.read(path) # => "bazbar" f.pos # => 3 f.pos = 3 f.write('foo') f.flush File.read(path) # => "bazfoo" f.pos # => 6 f.seek(-3, :END) f.write('bam') f.flush File.read(path) # => "bazbam" f.pos # => 6 f.pos = 8 f.write('bah') # Zero padding as needed. f.flush File.read(path) # => "bazbam\u0000\u0000bah" f.pos # => 11
File may be read anywhere (even past end-of-file); see IO#rewind
, IO#pos=
, IO#seek
:
f.rewind # => 0 f.read # => "bazbam\u0000\u0000bah" f.pos = 3 # => 3 f.read # => "bam\u0000\u0000bah" f.seek(-3, :END) # => 0 f.read # => "bah"
'a+'
:
File’s initial write position is 0:
path = 't.tmp' FileUtils.rm_f(path) f = File.new(path, 'a+') f.pos # => 0
Writing occurs only at end-of-file:
f.write('foo') f.pos # => 3 f.write('bar') f.pos # => 6 f.flush File.read(path) # => "foobar" f.rewind f.write('baz') f.flush File.read(path) # => "foobarbaz"
File may be read anywhere (even past end-of-file); see IO#rewind
, IO#pos=
, IO#seek
:
f.rewind f.read # => "foobarbaz" f.pos = 3 f.read # => "barbaz" f.seek(-3, :END) f.read # => "baz" f.pos = 800 f.read # => ""
To specify whether data is to be treated as text or as binary data, either of the following may be suffixed to any of the string read/write modes above:
't'
: Text data; sets the default external encoding to Encoding::UTF_8
; on Windows, enables conversion between EOL and CRLF and enables interpreting 0x1A
as an end-of-file marker.
'b'
: Binary data; sets the default external encoding to Encoding::ASCII_8BIT
; on Windows, suppresses conversion between EOL and CRLF and disables interpreting 0x1A
as an end-of-file marker.
If neither is given, the stream defaults to text data.
Examples:
File.new('t.txt', 'rt') File.new('t.dat', 'rb')
When the data mode is specified, the read/write mode may not be omitted, and the data mode must precede the file-create mode, if given:
File.new('t.dat', 'b') # Raises an exception. File.new('t.dat', 'rxb') # Raises an exception.
The following may be suffixed to any writable string mode above:
'x'
: Creates the file if it does not exist; raises an exception if the file exists.
Example:
File.new('t.tmp', 'wx')
When the file-create mode is specified, the read/write mode may not be omitted, and the file-create mode must follow the data mode:
File.new('t.dat', 'x') # Raises an exception. File.new('t.dat', 'rxb') # Raises an exception.
When mode is an integer it must be one or more of the following constants, which may be combined by the bitwise OR operator |
:
File::RDONLY
: Open for reading only.
File::WRONLY
: Open for writing only.
File::RDWR
: Open for reading and writing.
File::APPEND
: Open for appending only.
Examples:
File.new('t.txt', File::RDONLY) File.new('t.tmp', File::RDWR | File::CREAT | File::EXCL)
Note: Method
IO#set_encoding
does not allow the mode to be specified as an integer.
These constants may also be ORed into the integer mode:
File::CREAT
: Create file if it does not exist.
File::EXCL
: Raise an exception if File::CREAT
is given and the file exists.
Data mode cannot be specified as an integer. When the stream access mode is given as an integer, the data mode is always text, never binary.
Note that although there is a constant File::BINARY
, setting its value in an integer stream mode has no effect; this is because, as documented in File::Constants
, the File::BINARY
value disables line code conversion, but does not change the external encoding.
Any of the string modes above may specify encodings - either external encoding only or both external and internal encodings - by appending one or both encoding names, separated by colons:
f = File.new('t.dat', 'rb') f.external_encoding # => #<Encoding:ASCII-8BIT> f.internal_encoding # => nil f = File.new('t.dat', 'rb:UTF-16') f.external_encoding # => #<Encoding:UTF-16 (dummy)> f.internal_encoding # => nil f = File.new('t.dat', 'rb:UTF-16:UTF-16') f.external_encoding # => #<Encoding:UTF-16 (dummy)> f.internal_encoding # => #<Encoding:UTF-16> f.close
The numerous encoding names are available in array Encoding.name_list
:
Encoding.name_list.take(3) # => ["ASCII-8BIT", "UTF-8", "US-ASCII"]
When the external encoding is set, strings read are tagged by that encoding when reading, and strings written are converted to that encoding when writing.
When both external and internal encodings are set, strings read are converted from external to internal encoding, and strings written are converted from internal to external encoding. For further details about transcoding input and output, see Encodings.
If the external encoding is 'BOM|UTF-8'
, 'BOM|UTF-16LE'
or 'BOM|UTF16-BE'
, Ruby checks for a Unicode BOM in the input document to help determine the encoding. For UTF-16 encodings the file open mode must be binary. If the BOM is found, it is stripped and the external encoding from the BOM is used.
Note that the BOM-style encoding option is case insensitive, so 'bom|utf-8'
is also valid.
A File object has permissions, an octal integer representing the permissions of an actual file in the underlying platform.
Note that file permissions are quite different from the mode of a file stream (File object).
In a File object, the permissions are available thus, where method mode
, despite its name, returns permissions:
f = File.new('t.txt') f.lstat.mode.to_s(8) # => "100644"
On a Unix-based operating system, the three low-order octal digits represent the permissions for owner (6), group (4), and world (4). The triplet of bits in each octal digit represent, respectively, read, write, and execute permissions.
Permissions 0644
thus represent read-write access for owner and read-only access for group and world. See man pages open(2) and chmod(2).
For a directory, the meaning of the execute bit changes: when set, the directory can be searched.
Higher-order bits in permissions may indicate the type of file (plain, directory, pipe, socket, etc.) and various other special features.
On non-Posix operating systems, permissions may include only read-only or read-write, in which case, the remaining permission will resemble typical values. On Windows, for instance, the default permissions are 0644
; The only change that can be made is to make the file read-only, which is reported as 0444
.
For a method that actually creates a file in the underlying platform (as opposed to merely creating a File object), permissions may be specified:
File.new('t.tmp', File::CREAT, 0644) File.new('t.tmp', File::CREAT, 0444)
Permissions may also be changed:
f = File.new('t.tmp', File::CREAT, 0444) f.chmod(0644) f.chmod(0444)
Various constants for use in File and IO
methods may be found in module File::Constants
; an array of their names is returned by File::Constants.constants
.
First, what’s elsewhere. Class File:
Inherits from class IO, in particular, methods for creating, reading, and writing files
Includes module FileTest
, which provides dozens of additional methods.
Here, class File provides methods that are useful for:
::new
: Opens the file at the given path; returns the file.
::open
: Same as ::new
, but when given a block will yield the file to the block, and close the file upon exiting the block.
::link
: Creates a new name for an existing file using a hard link.
::mkfifo
: Returns the FIFO file created at the given path.
::symlink
: Creates a symbolic link for the given file path.
Paths
::absolute_path
: Returns the absolute file path for the given path.
::absolute_path?
: Returns whether the given path is the absolute file path.
::basename
: Returns the last component of the given file path.
::dirname
: Returns all but the last component of the given file path.
::expand_path
: Returns the absolute file path for the given path, expanding ~
for a home directory.
::extname
: Returns the file extension for the given file path.
::fnmatch?
(aliased as ::fnmatch
): Returns whether the given file path matches the given pattern.
::join
: Joins path components into a single path string.
::path
: Returns the string representation of the given path.
::readlink
: Returns the path to the file at the given symbolic link.
::realdirpath
: Returns the real path for the given file path, where the last component need not exist.
::realpath
: Returns the real path for the given file path, where all components must exist.
::split
: Returns an array of two strings: the directory name and basename of the file at the given path.
path
(aliased as to_path
): Returns the string representation of the given path.
Times
::atime
: Returns a Time
for the most recent access to the given file.
::birthtime
: Returns a Time
for the creation of the given file.
::ctime
: Returns a Time
for the metadata change of the given file.
::mtime
: Returns a Time
for the most recent data modification to the content of the given file.
mtime
: Returns a Time
for the most recent data modification to the content of self
.
Types
::blockdev?
: Returns whether the file at the given path is a block device.
::chardev?
: Returns whether the file at the given path is a character device.
::directory?
: Returns whether the file at the given path is a directory.
::executable?
: Returns whether the file at the given path is executable by the effective user and group of the current process.
::executable_real?
: Returns whether the file at the given path is executable by the real user and group of the current process.
::exist?
: Returns whether the file at the given path exists.
::file?
: Returns whether the file at the given path is a regular file.
::ftype
: Returns a string giving the type of the file at the given path.
::grpowned?
: Returns whether the effective group of the current process owns the file at the given path.
::identical?
: Returns whether the files at two given paths are identical.
::lstat
: Returns the File::Stat
object for the last symbolic link in the given path.
::owned?
: Returns whether the effective user of the current process owns the file at the given path.
::pipe?
: Returns whether the file at the given path is a pipe.
::readable?
: Returns whether the file at the given path is readable by the effective user and group of the current process.
::readable_real?
: Returns whether the file at the given path is readable by the real user and group of the current process.
::setgid?
: Returns whether the setgid bit is set for the file at the given path.
::setuid?
: Returns whether the setuid bit is set for the file at the given path.
::socket?
: Returns whether the file at the given path is a socket.
::stat
: Returns the File::Stat
object for the file at the given path.
::sticky?
: Returns whether the file at the given path has its sticky bit set.
::symlink?
: Returns whether the file at the given path is a symbolic link.
::umask
: Returns the umask value for the current process.
::world_readable?
: Returns whether the file at the given path is readable by others.
::world_writable?
: Returns whether the file at the given path is writable by others.
::writable?
: Returns whether the file at the given path is writable by the effective user and group of the current process.
::writable_real?
: Returns whether the file at the given path is writable by the real user and group of the current process.
lstat
: Returns the File::Stat
object for the last symbolic link in the path for self
.
Contents
::empty?
(aliased as ::zero?
): Returns whether the file at the given path exists and is empty.
::size
: Returns the size (bytes) of the file at the given path.
::size?
: Returns nil
if there is no file at the given path, or if that file is empty; otherwise returns the file size (bytes).
size
: Returns the size (bytes) of self
.
::chmod
: Changes permissions of the file at the given path.
::chown
: Change ownership of the file at the given path.
::lchmod
: Changes permissions of the last symbolic link in the given path.
::lchown
: Change ownership of the last symbolic in the given path.
::lutime
: For each given file path, sets the access time and modification time of the last symbolic link in the path.
::rename
: Moves the file at one given path to another given path.
::utime
: Sets the access time and modification time of each file at the given paths.
flock
: Locks or unlocks self
.
::truncate
: Truncates the file at the given file path to the given size.
::unlink
(aliased as ::delete
): Deletes the file for each given file path.
truncate
: Truncates self
to the given size.
Raised when a method is called on a receiver which doesn’t have it defined and also fails to respond with method_missing
.
"hello".to_ary
raises the exception:
NoMethodError: undefined method `to_ary' for an instance of String
Raised when memory allocation fails.
SystemCallError
is the base class for all low-level platform-dependent errors.
The errors available on the current platform are subclasses of SystemCallError
and are defined in the Errno
module.
File.open("does/not/exist")
raises the exception:
Errno::ENOENT: No such file or directory - does/not/exist