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.
Generate a JSON
document from the Ruby data structure obj and return it. state is * a JSON::State object,
or a Hash
like object (responding to to_hash),
an object convertible into a hash by a to_h method,
that is used as or to configure a State object.
It defaults to a state object, that creates the shortest possible JSON
text in one line, checks for circular data structures and doesn’t allow NaN
, Infinity
, and -Infinity.
A state hash can have the following keys:
indent: a string used to indent levels (default: ”),
space: a string that is put after, a : or , delimiter (default: ”),
space_before: a string that is put before a : pair delimiter (default: ”),
object_nl: a string that is put at the end of a JSON
object (default: ”),
array_nl: a string that is put at the end of a JSON
array (default: ”),
allow_nan: true if NaN
, Infinity
, and -Infinity should be generated, otherwise an exception is thrown if these values are encountered. This options defaults to false.
max_nesting: The maximum depth of nesting allowed in the data structures from which JSON
is to be generated. Disable depth checking with :max_nesting => false, it defaults to 100.
See also the fast_generate
for the fastest creation method with the least amount of sanity checks, and the pretty_generate
method for some defaults for pretty output.
Encodes string using Ruby’s 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.
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.
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 two arguments 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.
Closes the syslog facility. Raises a runtime exception if it is not open.
Calculates Adler-32 checksum for string
, and returns updated value of adler
. If string
is omitted, it returns the Adler-32 initial value. If adler
is omitted, it assumes that the initial value is given to adler
.
Example usage:
require "zlib" data = "foo" puts "Adler32 checksum: #{Zlib.adler32(data).to_s(16)}" #=> Adler32 checksum: 2820145
Returns true
if the named file exists and has a zero size.
file_name can be an IO
object.
Returns true
if the named file exists and has a zero size.
file_name can be an IO
object.
Returns true
if the named file is a character device.
file_name can be an IO
object.
Returns true
if the named file has the setuid bit set.
file_name can be an IO
object.
Returns true
if the named file has the setgid bit set.
file_name 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