Returns true
if the named file is readable by the effective user and group id of this process. See eaccess(3).
Note that some OS-level security features may cause this to return true even though the file is not readable by the effective user/group.
Returns true
if the named file exists and has a zero size.
file_name can be an IO
object.
Returns the time used to execute the given block as a Benchmark::Tms
object. Takes label
option.
require 'benchmark' n = 1000000 time = Benchmark.measure do n.times { a = "1" } end puts time
Generates:
0.220000 0.000000 0.220000 ( 0.227313)
Returns the elapsed real time used to execute the given block. The unit of time is seconds.
Benchmark.realtime { "a" * 1_000_000_000 } #=> 0.5098029999935534
Returns the time used to execute the given block as a Benchmark::Tms
object. Takes label
option.
require 'benchmark' n = 1000000 time = Benchmark.measure do n.times { a = "1" } end puts time
Generates:
0.220000 0.000000 0.220000 ( 0.227313)
Returns the elapsed real time used to execute the given block. The unit of time is seconds.
Benchmark.realtime { "a" * 1_000_000_000 } #=> 0.5098029999935534
The directory prefix this RubyGems was installed at. If your prefix is in a standard location (ie, rubygems is installed where you’d expect it to be), then prefix returns nil.
Changes permissions on the entries at the paths given in list
(a single path or an array of paths) to the permissions given by mode
; returns list
if it is an array, [list]
otherwise:
Modifies each entry that is a regular file using File.chmod
.
Modifies each entry that is a symbolic link using File.lchmod
.
Argument list
or its elements should be interpretable as paths.
Argument mode
may be either an integer or a string:
Integer mode
: represents the permission bits to be set:
FileUtils.chmod(0755, 'src0.txt') FileUtils.chmod(0644, ['src0.txt', 'src0.dat'])
String mode
: represents the permissions to be set:
The string is of the form [targets][[operator][perms[,perms]]
, where:
targets
may be any combination of these letters:
'u'
: permissions apply to the file’s owner.
'g'
: permissions apply to users in the file’s group.
'o'
: permissions apply to other users not in the file’s group.
'a'
(the default): permissions apply to all users.
operator
may be one of these letters:
'+'
: adds permissions.
'-'
: removes permissions.
'='
: sets (replaces) permissions.
perms
(may be repeated, with separating commas) may be any combination of these letters:
'r'
: Read.
'w'
: Write.
'x'
: Execute (search, for a directory).
'X'
: Search (for a directories only; must be used with '+'
)
's'
: Uid or gid.
't'
: Sticky bit.
Examples:
FileUtils.chmod('u=wrx,go=rx', 'src1.txt') FileUtils.chmod('u=wrx,go=rx', '/usr/bin/ruby')
Keyword arguments:
noop: true
- does not change permissions; returns nil
.
verbose: true
- prints an equivalent command:
FileUtils.chmod(0755, 'src0.txt', noop: true, verbose: true) FileUtils.chmod(0644, ['src0.txt', 'src0.dat'], noop: true, verbose: true) FileUtils.chmod('u=wrx,go=rx', 'src1.txt', noop: true, verbose: true) FileUtils.chmod('u=wrx,go=rx', '/usr/bin/ruby', noop: true, verbose: true)
Output:
chmod 755 src0.txt chmod 644 src0.txt src0.dat chmod u=wrx,go=rx src1.txt chmod u=wrx,go=rx /usr/bin/ruby
Related: FileUtils.chmod_R
.
Changes permissions on the entries at the paths given in list
(a single path or an array of paths) to the permissions given by mode
; returns list
if it is an array, [list]
otherwise:
Modifies each entry that is a regular file using File.chmod
.
Modifies each entry that is a symbolic link using File.lchmod
.
Argument list
or its elements should be interpretable as paths.
Argument mode
may be either an integer or a string:
Integer mode
: represents the permission bits to be set:
FileUtils.chmod(0755, 'src0.txt') FileUtils.chmod(0644, ['src0.txt', 'src0.dat'])
String mode
: represents the permissions to be set:
The string is of the form [targets][[operator][perms[,perms]]
, where:
targets
may be any combination of these letters:
'u'
: permissions apply to the file’s owner.
'g'
: permissions apply to users in the file’s group.
'o'
: permissions apply to other users not in the file’s group.
'a'
(the default): permissions apply to all users.
operator
may be one of these letters:
'+'
: adds permissions.
'-'
: removes permissions.
'='
: sets (replaces) permissions.
perms
(may be repeated, with separating commas) may be any combination of these letters:
'r'
: Read.
'w'
: Write.
'x'
: Execute (search, for a directory).
'X'
: Search (for a directories only; must be used with '+'
)
's'
: Uid or gid.
't'
: Sticky bit.
Examples:
FileUtils.chmod('u=wrx,go=rx', 'src1.txt') FileUtils.chmod('u=wrx,go=rx', '/usr/bin/ruby')
Keyword arguments:
noop: true
- does not change permissions; returns nil
.
verbose: true
- prints an equivalent command:
FileUtils.chmod(0755, 'src0.txt', noop: true, verbose: true) FileUtils.chmod(0644, ['src0.txt', 'src0.dat'], noop: true, verbose: true) FileUtils.chmod('u=wrx,go=rx', 'src1.txt', noop: true, verbose: true) FileUtils.chmod('u=wrx,go=rx', '/usr/bin/ruby', noop: true, verbose: true)
Output:
chmod 755 src0.txt chmod 644 src0.txt src0.dat chmod u=wrx,go=rx src1.txt chmod u=wrx,go=rx /usr/bin/ruby
Related: FileUtils.chmod_R
.
Like FileUtils.chmod
, but changes permissions recursively.
Like FileUtils.chmod
, but changes permissions recursively.
Returns time stamp of the target
file if it exists and is newer than or equal to all of times
.
Basically a wrapper for Open3.popen3
that:
Creates a child process, by calling Open3.popen3
with the given arguments (except for certain entries in hash options
; see below).
Returns as strings stdout_s
and stderr_s
the standard output and standard error of the child process.
Returns as status
a Process::Status
object that represents the exit status of the child process.
Returns the array [stdout_s, stderr_s, status]
:
stdout_s, stderr_s, status = Open3.capture3('echo "Foo"') # => ["Foo\n", "", #<Process::Status: pid 2281954 exit 0>]
Like Process.spawn
, this method has potential security vulnerabilities if called with untrusted input; see Command Injection.
Unlike Process.spawn
, this method waits for the child process to exit before returning, so the caller need not do so.
If the first argument is a hash, it becomes leading argument env
in the call to Open3.popen3
; see Execution Environment.
If the last argument is a hash, it becomes trailing argument options
in the call to Open3.popen3
; see Execution Options.
The hash options
is given; two options have local effect in method Open3.capture3
:
If entry options[:stdin_data]
exists, the entry is removed and its string value is sent to the command’s standard input:
Open3.capture3('tee', stdin_data: 'Foo') # => ["Foo", "", #<Process::Status: pid 2319575 exit 0>]
If entry options[:binmode]
exists, the entry is removed and the internal streams are set to binary mode.
The single required argument is one of the following:
command_line
if it is a string, and if it begins with a shell reserved word or special built-in, or if it contains one or more metacharacters.
exe_path
otherwise.
Argument command_line
String argument command_line
is a command line to be passed to a shell; it must begin with a shell reserved word, begin with a special built-in, or contain meta characters:
Open3.capture3('if true; then echo "Foo"; fi') # Shell reserved word. # => ["Foo\n", "", #<Process::Status: pid 2282025 exit 0>] Open3.capture3('echo') # Built-in. # => ["\n", "", #<Process::Status: pid 2282092 exit 0>] Open3.capture3('date > date.tmp') # Contains meta character. # => ["", "", #<Process::Status: pid 2282110 exit 0>]
The command line may also contain arguments and options for the command:
Open3.capture3('echo "Foo"') # => ["Foo\n", "", #<Process::Status: pid 2282092 exit 0>]
Argument exe_path
Argument exe_path
is one of the following:
The string path to an executable to be called.
A 2-element array containing the path to an executable and the string to be used as the name of the executing process.
Example:
Open3.capture3('/usr/bin/date') # => ["Thu Sep 28 05:03:51 PM CDT 2023\n", "", #<Process::Status: pid 2282300 exit 0>]
Ruby invokes the executable directly, with no shell and no shell expansion:
Open3.capture3('doesnt_exist') # Raises Errno::ENOENT
If one or more args
is given, each is an argument or option to be passed to the executable:
Open3.capture3('echo', 'C #') # => ["C #\n", "", #<Process::Status: pid 2282368 exit 0>] Open3.capture3('echo', 'hello', 'world') # => ["hello world\n", "", #<Process::Status: pid 2282372 exit 0>]
Basically a wrapper for Open3.popen3
that:
Creates a child process, by calling Open3.popen3
with the given arguments (except for certain entries in hash options
; see below).
Returns as strings stdout_s
and stderr_s
the standard output and standard error of the child process.
Returns as status
a Process::Status
object that represents the exit status of the child process.
Returns the array [stdout_s, stderr_s, status]
:
stdout_s, stderr_s, status = Open3.capture3('echo "Foo"') # => ["Foo\n", "", #<Process::Status: pid 2281954 exit 0>]
Like Process.spawn
, this method has potential security vulnerabilities if called with untrusted input; see Command Injection.
Unlike Process.spawn
, this method waits for the child process to exit before returning, so the caller need not do so.
If the first argument is a hash, it becomes leading argument env
in the call to Open3.popen3
; see Execution Environment.
If the last argument is a hash, it becomes trailing argument options
in the call to Open3.popen3
; see Execution Options.
The hash options
is given; two options have local effect in method Open3.capture3
:
If entry options[:stdin_data]
exists, the entry is removed and its string value is sent to the command’s standard input:
Open3.capture3('tee', stdin_data: 'Foo') # => ["Foo", "", #<Process::Status: pid 2319575 exit 0>]
If entry options[:binmode]
exists, the entry is removed and the internal streams are set to binary mode.
The single required argument is one of the following:
command_line
if it is a string, and if it begins with a shell reserved word or special built-in, or if it contains one or more metacharacters.
exe_path
otherwise.
Argument command_line
String argument command_line
is a command line to be passed to a shell; it must begin with a shell reserved word, begin with a special built-in, or contain meta characters:
Open3.capture3('if true; then echo "Foo"; fi') # Shell reserved word. # => ["Foo\n", "", #<Process::Status: pid 2282025 exit 0>] Open3.capture3('echo') # Built-in. # => ["\n", "", #<Process::Status: pid 2282092 exit 0>] Open3.capture3('date > date.tmp') # Contains meta character. # => ["", "", #<Process::Status: pid 2282110 exit 0>]
The command line may also contain arguments and options for the command:
Open3.capture3('echo "Foo"') # => ["Foo\n", "", #<Process::Status: pid 2282092 exit 0>]
Argument exe_path
Argument exe_path
is one of the following:
The string path to an executable to be called.
A 2-element array containing the path to an executable and the string to be used as the name of the executing process.
Example:
Open3.capture3('/usr/bin/date') # => ["Thu Sep 28 05:03:51 PM CDT 2023\n", "", #<Process::Status: pid 2282300 exit 0>]
Ruby invokes the executable directly, with no shell and no shell expansion:
Open3.capture3('doesnt_exist') # Raises Errno::ENOENT
If one or more args
is given, each is an argument or option to be passed to the executable:
Open3.capture3('echo', 'C #') # => ["C #\n", "", #<Process::Status: pid 2282368 exit 0>] Open3.capture3('echo', 'hello', 'world') # => ["hello world\n", "", #<Process::Status: pid 2282372 exit 0>]
Basically a wrapper for Open3.popen3
that:
Creates a child process, by calling Open3.popen3
with the given arguments (except for certain entries in hash options
; see below).
Returns as string stdout_s
the standard output of the child process.
Returns as status
a Process::Status
object that represents the exit status of the child process.
Returns the array [stdout_s, status]
:
stdout_s, status = Open3.capture2('echo "Foo"') # => ["Foo\n", #<Process::Status: pid 2326047 exit 0>]
Like Process.spawn
, this method has potential security vulnerabilities if called with untrusted input; see Command Injection.
Unlike Process.spawn
, this method waits for the child process to exit before returning, so the caller need not do so.
If the first argument is a hash, it becomes leading argument env
in the call to Open3.popen3
; see Execution Environment.
If the last argument is a hash, it becomes trailing argument options
in the call to Open3.popen3
; see Execution Options.
The hash options
is given; two options have local effect in method Open3.capture2
:
If entry options[:stdin_data]
exists, the entry is removed and its string value is sent to the command’s standard input:
Open3.capture2('tee', stdin_data: 'Foo') # => ["Foo", #<Process::Status: pid 2326087 exit 0>]
If entry options[:binmode]
exists, the entry is removed and the internal streams are set to binary mode.
The single required argument is one of the following:
command_line
if it is a string, and if it begins with a shell reserved word or special built-in, or if it contains one or more metacharacters.
exe_path
otherwise.
Argument command_line
String argument command_line
is a command line to be passed to a shell; it must begin with a shell reserved word, begin with a special built-in, or contain meta characters:
Open3.capture2('if true; then echo "Foo"; fi') # Shell reserved word. # => ["Foo\n", #<Process::Status: pid 2326131 exit 0>] Open3.capture2('echo') # Built-in. # => ["\n", #<Process::Status: pid 2326139 exit 0>] Open3.capture2('date > date.tmp') # Contains meta character. # => ["", #<Process::Status: pid 2326174 exit 0>]
The command line may also contain arguments and options for the command:
Open3.capture2('echo "Foo"') # => ["Foo\n", #<Process::Status: pid 2326183 exit 0>]
Argument exe_path
Argument exe_path
is one of the following:
The string path to an executable to be called.
A 2-element array containing the path to an executable and the string to be used as the name of the executing process.
Example:
Open3.capture2('/usr/bin/date') # => ["Fri Sep 29 01:00:39 PM CDT 2023\n", #<Process::Status: pid 2326222 exit 0>]
Ruby invokes the executable directly, with no shell and no shell expansion:
Open3.capture2('doesnt_exist') # Raises Errno::ENOENT
If one or more args
is given, each is an argument or option to be passed to the executable:
Open3.capture2('echo', 'C #') # => ["C #\n", #<Process::Status: pid 2326267 exit 0>] Open3.capture2('echo', 'hello', 'world') # => ["hello world\n", #<Process::Status: pid 2326299 exit 0>]
Basically a wrapper for Open3.popen3
that:
Creates a child process, by calling Open3.popen3
with the given arguments (except for certain entries in hash options
; see below).
Returns as string stdout_s
the standard output of the child process.
Returns as status
a Process::Status
object that represents the exit status of the child process.
Returns the array [stdout_s, status]
:
stdout_s, status = Open3.capture2('echo "Foo"') # => ["Foo\n", #<Process::Status: pid 2326047 exit 0>]
Like Process.spawn
, this method has potential security vulnerabilities if called with untrusted input; see Command Injection.
Unlike Process.spawn
, this method waits for the child process to exit before returning, so the caller need not do so.
If the first argument is a hash, it becomes leading argument env
in the call to Open3.popen3
; see Execution Environment.
If the last argument is a hash, it becomes trailing argument options
in the call to Open3.popen3
; see Execution Options.
The hash options
is given; two options have local effect in method Open3.capture2
:
If entry options[:stdin_data]
exists, the entry is removed and its string value is sent to the command’s standard input:
Open3.capture2('tee', stdin_data: 'Foo') # => ["Foo", #<Process::Status: pid 2326087 exit 0>]
If entry options[:binmode]
exists, the entry is removed and the internal streams are set to binary mode.
The single required argument is one of the following:
command_line
if it is a string, and if it begins with a shell reserved word or special built-in, or if it contains one or more metacharacters.
exe_path
otherwise.
Argument command_line
String argument command_line
is a command line to be passed to a shell; it must begin with a shell reserved word, begin with a special built-in, or contain meta characters:
Open3.capture2('if true; then echo "Foo"; fi') # Shell reserved word. # => ["Foo\n", #<Process::Status: pid 2326131 exit 0>] Open3.capture2('echo') # Built-in. # => ["\n", #<Process::Status: pid 2326139 exit 0>] Open3.capture2('date > date.tmp') # Contains meta character. # => ["", #<Process::Status: pid 2326174 exit 0>]
The command line may also contain arguments and options for the command:
Open3.capture2('echo "Foo"') # => ["Foo\n", #<Process::Status: pid 2326183 exit 0>]
Argument exe_path
Argument exe_path
is one of the following:
The string path to an executable to be called.
A 2-element array containing the path to an executable and the string to be used as the name of the executing process.
Example:
Open3.capture2('/usr/bin/date') # => ["Fri Sep 29 01:00:39 PM CDT 2023\n", #<Process::Status: pid 2326222 exit 0>]
Ruby invokes the executable directly, with no shell and no shell expansion:
Open3.capture2('doesnt_exist') # Raises Errno::ENOENT
If one or more args
is given, each is an argument or option to be passed to the executable:
Open3.capture2('echo', 'C #') # => ["C #\n", #<Process::Status: pid 2326267 exit 0>] Open3.capture2('echo', 'hello', 'world') # => ["hello world\n", #<Process::Status: pid 2326299 exit 0>]
Basically a wrapper for Open3.popen3
that:
Creates a child process, by calling Open3.popen3
with the given arguments (except for certain entries in hash options
; see below).
Returns as string stdout_and_stderr_s
the merged standard output and standard error of the child process.
Returns as status
a Process::Status
object that represents the exit status of the child process.
Returns the array [stdout_and_stderr_s, status]
:
stdout_and_stderr_s, status = Open3.capture2e('echo "Foo"') # => ["Foo\n", #<Process::Status: pid 2371692 exit 0>]
Like Process.spawn
, this method has potential security vulnerabilities if called with untrusted input; see Command Injection.
Unlike Process.spawn
, this method waits for the child process to exit before returning, so the caller need not do so.
If the first argument is a hash, it becomes leading argument env
in the call to Open3.popen3
; see Execution Environment.
If the last argument is a hash, it becomes trailing argument options
in the call to Open3.popen3
; see Execution Options.
The hash options
is given; two options have local effect in method Open3.capture2e
:
If entry options[:stdin_data]
exists, the entry is removed and its string value is sent to the command’s standard input:
Open3.capture2e('tee', stdin_data: 'Foo') # => ["Foo", #<Process::Status: pid 2371732 exit 0>]
If entry options[:binmode]
exists, the entry is removed and the internal streams are set to binary mode.
The single required argument is one of the following:
command_line
if it is a string, and if it begins with a shell reserved word or special built-in, or if it contains one or more metacharacters.
exe_path
otherwise.
Argument command_line
String argument command_line
is a command line to be passed to a shell; it must begin with a shell reserved word, begin with a special built-in, or contain meta characters:
Open3.capture2e('if true; then echo "Foo"; fi') # Shell reserved word. # => ["Foo\n", #<Process::Status: pid 2371740 exit 0>] Open3.capture2e('echo') # Built-in. # => ["\n", #<Process::Status: pid 2371774 exit 0>] Open3.capture2e('date > date.tmp') # Contains meta character. # => ["", #<Process::Status: pid 2371812 exit 0>]
The command line may also contain arguments and options for the command:
Open3.capture2e('echo "Foo"') # => ["Foo\n", #<Process::Status: pid 2326183 exit 0>]
Argument exe_path
Argument exe_path
is one of the following:
The string path to an executable to be called.
A 2-element array containing the path to an executable and the string to be used as the name of the executing process.
Example:
Open3.capture2e('/usr/bin/date') # => ["Sat Sep 30 09:01:46 AM CDT 2023\n", #<Process::Status: pid 2371820 exit 0>]
Ruby invokes the executable directly, with no shell and no shell expansion:
Open3.capture2e('doesnt_exist') # Raises Errno::ENOENT
If one or more args
is given, each is an argument or option to be passed to the executable:
Open3.capture2e('echo', 'C #') # => ["C #\n", #<Process::Status: pid 2371856 exit 0>] Open3.capture2e('echo', 'hello', 'world') # => ["hello world\n", #<Process::Status: pid 2371894 exit 0>]
Basically a wrapper for Open3.popen3
that:
Creates a child process, by calling Open3.popen3
with the given arguments (except for certain entries in hash options
; see below).
Returns as string stdout_and_stderr_s
the merged standard output and standard error of the child process.
Returns as status
a Process::Status
object that represents the exit status of the child process.
Returns the array [stdout_and_stderr_s, status]
:
stdout_and_stderr_s, status = Open3.capture2e('echo "Foo"') # => ["Foo\n", #<Process::Status: pid 2371692 exit 0>]
Like Process.spawn
, this method has potential security vulnerabilities if called with untrusted input; see Command Injection.
Unlike Process.spawn
, this method waits for the child process to exit before returning, so the caller need not do so.
If the first argument is a hash, it becomes leading argument env
in the call to Open3.popen3
; see Execution Environment.
If the last argument is a hash, it becomes trailing argument options
in the call to Open3.popen3
; see Execution Options.
The hash options
is given; two options have local effect in method Open3.capture2e
:
If entry options[:stdin_data]
exists, the entry is removed and its string value is sent to the command’s standard input:
Open3.capture2e('tee', stdin_data: 'Foo') # => ["Foo", #<Process::Status: pid 2371732 exit 0>]
If entry options[:binmode]
exists, the entry is removed and the internal streams are set to binary mode.
The single required argument is one of the following:
command_line
if it is a string, and if it begins with a shell reserved word or special built-in, or if it contains one or more metacharacters.
exe_path
otherwise.
Argument command_line
String argument command_line
is a command line to be passed to a shell; it must begin with a shell reserved word, begin with a special built-in, or contain meta characters:
Open3.capture2e('if true; then echo "Foo"; fi') # Shell reserved word. # => ["Foo\n", #<Process::Status: pid 2371740 exit 0>] Open3.capture2e('echo') # Built-in. # => ["\n", #<Process::Status: pid 2371774 exit 0>] Open3.capture2e('date > date.tmp') # Contains meta character. # => ["", #<Process::Status: pid 2371812 exit 0>]
The command line may also contain arguments and options for the command:
Open3.capture2e('echo "Foo"') # => ["Foo\n", #<Process::Status: pid 2326183 exit 0>]
Argument exe_path
Argument exe_path
is one of the following:
The string path to an executable to be called.
A 2-element array containing the path to an executable and the string to be used as the name of the executing process.
Example:
Open3.capture2e('/usr/bin/date') # => ["Sat Sep 30 09:01:46 AM CDT 2023\n", #<Process::Status: pid 2371820 exit 0>]
Ruby invokes the executable directly, with no shell and no shell expansion:
Open3.capture2e('doesnt_exist') # Raises Errno::ENOENT
If one or more args
is given, each is an argument or option to be passed to the executable:
Open3.capture2e('echo', 'C #') # => ["C #\n", #<Process::Status: pid 2371856 exit 0>] Open3.capture2e('echo', 'hello', 'world') # => ["hello world\n", #<Process::Status: pid 2371894 exit 0>]
Returns a 2-element array containing the normalized signed float fraction
and integer exponent
of x
such that:
x = fraction * 2**exponent
See IEEE 754 double-precision binary floating-point format: binary64.
Domain: [-INFINITY, INFINITY]
.
Range
[-INFINITY, INFINITY]
.
Examples:
frexp(-INFINITY) # => [-Infinity, -1] frexp(-2.0) # => [-0.5, 2] frexp(-1.0) # => [-0.5, 1] frexp(0.0) # => [0.0, 0] frexp(1.0) # => [0.5, 1] frexp(2.0) # => [0.5, 2] frexp(INFINITY) # => [Infinity, -1]
Related: Math.ldexp
(inverse of Math.frexp
).
Returns location objects associated with the AST node. The returned array contains RubyVM::AbstractSyntaxTree::Location
.
Gets various OpenSSL options.
Sets various OpenSSL options. The options are a bit field and can be combined with the bitwise OR operator (|
). Available options are defined as constants in OpenSSL::SSL
that begin with OP_
.
For backwards compatibility, passing nil
has the same effect as passing OpenSSL::SSL::OP_ALL.
See also man page SSL_CTX_set_options(3).