Returns system configuration directory.
This is typically "/etc"
, but is modified by the prefix used when Ruby
was compiled. For example, if Ruby
is built and installed in /usr/local
, returns "/usr/local/etc"
on other platforms than Windows.
On Windows, this always returns the directory provided by the system.
Returns the system information obtained by uname system call.
The return value is a hash which has 5 keys at least:
:sysname, :nodename, :release, :version, :machine
Example:
require 'etc' require 'pp' pp Etc.uname #=> {:sysname=>"Linux", # :nodename=>"boron", # :release=>"2.6.18-6-xen-686", # :version=>"#1 SMP Thu Nov 5 19:54:42 UTC 2009", # :machine=>"i686"}
Returns system configuration variable using sysconf().
name should be a constant under Etc
which begins with SC_
.
The return value is an integer or nil. nil means indefinite limit. (sysconf() returns -1 but errno is not set.)
Etc.sysconf(Etc::SC_ARG_MAX) #=> 2097152 Etc.sysconf(Etc::SC_LOGIN_NAME_MAX) #=> 256
Returns system configuration variable using confstr().
name should be a constant under Etc
which begins with CS_
.
The return value is a string or nil. nil means no configuration-defined value. (confstr() returns 0 but errno is not set.)
Etc.confstr(Etc::CS_PATH) #=> "/bin:/usr/bin" # GNU/Linux Etc.confstr(Etc::CS_GNU_LIBC_VERSION) #=> "glibc 2.18" Etc.confstr(Etc::CS_GNU_LIBPTHREAD_VERSION) #=> "NPTL 2.18"
Encodes string using String.encode
.
Decode the given gzipped string
.
This method is almost equivalent to the following code:
def gunzip(string) sio = StringIO.new(string) gz = Zlib::GzipReader.new(sio, encoding: Encoding::ASCII_8BIT) gz.read ensure gz&.close end
See also Zlib.gzip
With string object
given, returns true
if path
is a string path leading to a directory, or to a symbolic link to a directory; false
otherwise:
File.directory?('.') # => true File.directory?('foo') # => false File.symlink('.', 'dirlink') # => 0 File.directory?('dirlink') # => true File.symlink('t,txt', 'filelink') # => 0 File.directory?('filelink') # => false
Argument path
can be an IO
object.
Returns true
if the named file has the sticky bit set.
file_name can be an IO
object.
Returns true
if the named files are identical.
file_1 and file_2 can be an IO
object.
open("a", "w") {} p File.identical?("a", "a") #=> true p File.identical?("a", "./a") #=> true File.link("a", "b") p File.identical?("a", "b") #=> true File.symlink("a", "c") p File.identical?("a", "c") #=> true open("d", "w") {} p File.identical?("a", "d") #=> false
Returns the number of times GC has occurred since the process started.
Sets or gets information about the current GC config.
Configuration parameters are GC implementation-specific and may change without notice.
This method can be called without parameters to retrieve the current config as a Hash
with Symbol
keys.
This method can also be called with a Hash
argument to assign values to valid config keys. Config keys missing from the passed Hash
will be left unmodified.
If a key/value pair is passed to this function that does not correspond to a valid config key for the GC implementation being used, no config will be updated, the key will be present in the returned Hash
, and its value will be nil
. This is to facilitate easy migration between GC implementations.
In both call-seqs, the return value of GC.config
will be a Hash
containing the most recent full configuration, i.e., all keys and values defined by the specific GC implementation being used. In the case of a config update, the return value will include the new values being updated.
This method is only expected to work on CRuby.
The GC.config
hash can also contain keys that are global and read-only. These keys are not specific to any one GC library implementation and attempting to write to them will raise ArgumentError
.
There is currently only one global, read-only key:
Returns a String
containing the name of the currently loaded GC library, if one has been loaded using RUBY_GC_LIBRARY
, and “default” in all other cases
GC libraries are expected to document their own configuration. Valid keys for Ruby’s default GC implementation are:
Controls whether the GC is allowed to run a full mark (young & old objects).
When true
, GC interleaves major and minor collections. This is the default. GC will function as intended.
When false
, the GC will never trigger a full marking cycle unless explicitly requested by user code. Instead, only a minor mark will run—only young objects will be marked. When the heap space is exhausted, new pages will be allocated immediately instead of running a full mark.
A flag will be set to notify that a full mark has been requested. This flag is accessible using GC.latest_gc_info(:need_major_by)
The user can trigger a major collection at any time using GC.start(full_mark: true)
When false
, Young to Old object promotion is disabled. For performance reasons, it is recommended to warm up an application using Process.warmup
before setting this parameter to false
.
Prints the amount of time the supplied block takes to run using the debug UI output.
Skips the current file or directory, restarting the loop with the next entry. If the current file is a directory, that directory will not be recursively entered. Meaningful only within the block associated with Find::find
.
See the Find
module documentation for an example.
Skips the current file or directory, restarting the loop with the next entry. If the current file is a directory, that directory will not be recursively entered. Meaningful only within the block associated with Find::find
.
See the Find
module documentation for an example.
Returns the singleton instance.
Perform an operation in a block, raising an error if it takes longer than sec
seconds to complete.
sec
Number of seconds to wait for the block to terminate. Any non-negative number or nil may be used, including Floats to specify fractional seconds. A value of 0 or nil
will execute the block without any timeout. Any negative number will raise an ArgumentError
.
klass
Exception
Class
to raise if the block fails to terminate in sec
seconds. Omitting will use the default, Timeout::Error
message
Error
message to raise with Exception
Class
. Omitting will use the default, “execution expired”
Returns the result of the block if the block completed before sec
seconds, otherwise throws an exception, based on the value of klass
.
The exception thrown to terminate the given block cannot be rescued inside the block unless klass
is given explicitly. However, the block can use ensure to prevent the handling of the exception. For that reason, this method cannot be relied on to enforce timeouts for untrusted blocks.
If a scheduler is defined, it will be used to handle the timeout by invoking Scheduler#timeout_after.
Note that this is both a method of module Timeout
, so you can include Timeout
into your classes so they have a timeout
method, as well as a module method, so you can call it directly as Timeout.timeout()
.
Perform an operation in a block, raising an error if it takes longer than sec
seconds to complete.
sec
Number of seconds to wait for the block to terminate. Any non-negative number or nil may be used, including Floats to specify fractional seconds. A value of 0 or nil
will execute the block without any timeout. Any negative number will raise an ArgumentError
.
klass
Exception
Class
to raise if the block fails to terminate in sec
seconds. Omitting will use the default, Timeout::Error
message
Error
message to raise with Exception
Class
. Omitting will use the default, “execution expired”
Returns the result of the block if the block completed before sec
seconds, otherwise throws an exception, based on the value of klass
.
The exception thrown to terminate the given block cannot be rescued inside the block unless klass
is given explicitly. However, the block can use ensure to prevent the handling of the exception. For that reason, this method cannot be relied on to enforce timeouts for untrusted blocks.
If a scheduler is defined, it will be used to handle the timeout by invoking Scheduler#timeout_after.
Note that this is both a method of module Timeout
, so you can include Timeout
into your classes so they have a timeout
method, as well as a module method, so you can call it directly as Timeout.timeout()
.
Returns the scheduling priority for specified process, process group, or user.
Argument kind
is one of:
Process::PRIO_PROCESS
: return priority for process.
Process::PRIO_PGRP
: return priority for process group.
Process::PRIO_USER
: return priority for user.
Argument id
is the ID for the process, process group, or user; zero specified the current ID for kind
.
Examples:
Process.getpriority(Process::PRIO_USER, 0) # => 19 Process.getpriority(Process::PRIO_PROCESS, 0) # => 19
Not available on all platforms.
See Process.getpriority
.
Examples:
Process.setpriority(Process::PRIO_USER, 0, 19) # => 0 Process.setpriority(Process::PRIO_PROCESS, 0, 19) # => 0 Process.getpriority(Process::PRIO_USER, 0) # => 19 Process.getpriority(Process::PRIO_PROCESS, 0) # => 19
Not available on all platforms.
Returns a Process::Tms
structure that contains user and system CPU times for the current process, and for its children processes:
Process.times # => #<struct Process::Tms utime=55.122118, stime=35.533068, cutime=0.0, cstime=0.002846>
The precision is platform-defined.
in [foo, bar, baz]
in InstanceVariableReadNode[name: Symbol] in { name: Symbol
}
Returns the form how EC::Point
data is encoded as ASN.1.
See also point_conversion_form=
.