Set
up the coverage measurement.
Note that this method does not start the measurement itself. Use Coverage.resume
to start the measurement.
You may want to use Coverage.start
to setup and then start the measurement.
Enables the coverage measurement. See the documentation of Coverage
class in detail. This is equivalent to Coverage.setup
and Coverage.resume
.
Resets the process of reading the /etc/passwd
file, so that the next call to ::getpwent
will return the first entry again.
Provides a convenient Ruby iterator which executes a block for each entry in the /etc/passwd
file.
The code block is passed an Passwd
struct.
See ::getpwent
above for details.
Example:
require 'etc' Etc.passwd {|u| puts u.name + " = " + u.gecos }
Resets the process of reading the /etc/group
file, so that the next call to ::getgrent
will return the first entry again.
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 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"
Creates a new handler that opens library
, and returns an instance of Fiddle::Handle
.
If nil
is given for the library
, Fiddle::Handle::DEFAULT is used, which is the equivalent to RTLD_DEFAULT. See man 3 dlopen
for more.
lib = Fiddle.dlopen(nil)
The default is dependent on OS, and provide a handle for all libraries already loaded. For example, in most cases you can use this to access libc
functions, or ruby functions like rb_str_new
.
See Fiddle::Handle.new
for more.
Creates a new handler that opens library
, and returns an instance of Fiddle::Handle
.
If nil
is given for the library
, Fiddle::Handle::DEFAULT is used, which is the equivalent to RTLD_DEFAULT. See man 3 dlopen
for more.
lib = Fiddle.dlopen(nil)
The default is dependent on OS, and provide a handle for all libraries already loaded. For example, in most cases you can use this to access libc
functions, or ruby functions like rb_str_new
.
See Fiddle::Handle.new
for more.
Returns a String containing the generated JSON data.
See also JSON.fast_generate
, JSON.pretty_generate
.
Argument obj
is the Ruby object to be converted to JSON.
Argument opts
, if given, contains a Hash of options for the generation. See Generating Options.
When obj
is an Array, returns a String containing a JSON array:
obj = ["foo", 1.0, true, false, nil] json = JSON.generate(obj) json # => '["foo",1.0,true,false,null]'
When obj
is a Hash, returns a String containing a JSON object:
obj = {foo: 0, bar: 's', baz: :bat} json = JSON.generate(obj) json # => '{"foo":0,"bar":"s","baz":"bat"}'
For examples of generating from other Ruby objects, see Generating JSON from Other Objects.
Raises an exception if any formatting option is not a String.
Raises an exception if obj
contains circular references:
a = []; b = []; a.push(b); b.push(a) # Raises JSON::NestingError (nesting of 100 is too deep): JSON.generate(a)
Encodes string using String.encode
.
Returns whether input encoding is EUC-JP or not.
Note don’t expect this return value is MatchData
.
Returns whether input encoding is EUC-JP or not.
Note don’t expect this return value is MatchData
.
Spawns the specified command on a newly allocated pty. You can also use the alias ::getpty
.
The command’s controlling tty is set to the slave device of the pty and its standard input/output/error is redirected to the slave device.
env
is an optional hash that provides additional environment variables to the spawned pty.
# sets FOO to "bar" PTY.spawn({"FOO"=>"bar"}, "printenv", "FOO") { |r,w,pid| p r.read } #=> "bar\r\n" # unsets FOO PTY.spawn({"FOO"=>nil}, "printenv", "FOO") { |r,w,pid| p r.read } #=> ""
command
and command_line
are the full commands to run, given a String
. Any additional arguments
will be passed to the command.
In the non-block form this returns an array of size three, [r, w, pid]
.
In the block form these same values will be yielded to the block:
Spawns the specified command on a newly allocated pty. You can also use the alias ::getpty
.
The command’s controlling tty is set to the slave device of the pty and its standard input/output/error is redirected to the slave device.
env
is an optional hash that provides additional environment variables to the spawned pty.
# sets FOO to "bar" PTY.spawn({"FOO"=>"bar"}, "printenv", "FOO") { |r,w,pid| p r.read } #=> "bar\r\n" # unsets FOO PTY.spawn({"FOO"=>nil}, "printenv", "FOO") { |r,w,pid| p r.read } #=> ""
command
and command_line
are the full commands to run, given a String
. Any additional arguments
will be passed to the command.
In the non-block form this returns an array of size three, [r, w, pid]
.
In the block form these same values will be yielded to the block:
Allocates a pty (pseudo-terminal).
In the block form, yields an array of two elements (master_io, slave_file
) and the value of the block is returned from open
.
The IO
and File
are both closed after the block completes if they haven’t been already closed.
PTY.open {|master, slave| p master #=> #<IO:masterpty:/dev/pts/1> p slave #=> #<File:/dev/pts/1> p slave.path #=> "/dev/pts/1" }
In the non-block form, returns a two element array, [master_io, slave_file]
.
master, slave = PTY.open # do something with master for IO, or the slave file
The arguments in both forms are:
master_io
the master of the pty, as an IO
.
slave_file
the slave of the pty, as a File
. The path to the terminal device is available via slave_file.path
IO#raw!
is usable to disable newline conversions:
require 'io/console' PTY.open {|m, s| s.raw! # ... }
Specifies a File
object input
that is input stream for Readline.readline
method.
Open the syslog facility. Raises a runtime exception if it is already open.
Can be called with or without a code block. If called with a block, the Syslog
object created is passed to the block.
If the syslog is already open, raises a RuntimeError
.
ident
is a String
which identifies the calling program.
options
is the logical OR of any of the following:
If there is an error while sending to the system logger, write directly to the console instead.
Open the connection now, rather than waiting for the first message to be written.
Don’t wait for any child processes created while logging messages. (Has no effect on Linux.)
Opposite of LOG_NDELAY; wait until a message is sent before opening the connection. (This is the default.)
Print the message to stderr as well as sending it to syslog. (Not in POSIX.1-2001.)
Include the current process ID with each message.
facility
describes the type of program opening the syslog, and is the logical OR of any of the following which are defined for the host OS:
Security or authorization. Deprecated, use LOG_AUTHPRIV instead.
Security or authorization messages which should be kept private.
System console message.
System task scheduler (cron or at).
A system daemon which has no facility value of its own.
An FTP server.
A kernel message (not sendable by user processes, so not of much use to Ruby, but listed here for completeness).
Line printer subsystem.
Mail delivery or transport subsystem.
Usenet news system.
Network Time
Protocol server.
General security message.
Messages generated internally by syslog.
Generic user-level message.
UUCP subsystem.
Locally-defined facilities.
Example:
Syslog.open("webrick", Syslog::LOG_PID, Syslog::LOG_DAEMON | Syslog::LOG_LOCAL3)
Returns true if the syslog is open.