Set
up option processing.
The options to support are passed to new() as an array of arrays. Each sub-array contains any number of String
option names which carry the same meaning, and one of the following flags:
Option does not take an argument.
Option always takes an argument.
Option may or may not take an argument.
The first option name is considered to be the preferred (canonical) name. Other than that, the elements of each sub-array can be in any order.
Creates a new ipaddr object either from a human readable IP address representation in string, or from a packed in_addr
value followed by an address family.
In the former case, the following are the valid formats that will be recognized: “address”, “address/prefixlen” and “address/mask”, where IPv6 address may be enclosed in square brackets (‘[’ and ‘]’). If a prefixlen or a mask is specified, it returns a masked IP address. Although the address family is determined automatically from a specified string, you can specify one explicitly by the optional second argument.
Otherwise an IP address is generated from a packed in_addr
value and an address family.
The IPAddr
class defines many methods and operators, and some of those, such as &, |, include? and ==, accept a string, or a packed in_addr
value instead of an IPAddr
object.
Creates a new XMP
object.
The top-level binding or, optional bind
parameter will be used when creating the workspace. See WorkSpace.new for more information.
This uses the :XMP
prompt mode, see Customizing the IRB Prompt at IRB
for full detail.
logdev
The log device. This is a filename (String
) or IO
object (typically STDOUT
, STDERR
, or an open file).
shift_age
Number of old log files to keep, or frequency of rotation (daily
, weekly
or monthly
). Default value is 0, which disables log file rotation.
shift_size
Maximum logfile size in bytes (only applies when shift_age
is a positive Integer
). Defaults to 1048576
(1MB).
level
Logging severity threshold. Default values is Logger::DEBUG.
progname
Program name to include in log messages. Default value is nil.
formatter
Logging formatter. Default values is an instance of Logger::Formatter.
datetime_format
Date
and time format. Default value is ‘%Y-%m-%d %H:%M:%S’.
binmode
Use binary mode on the log device. Default value is false.
shift_period_suffix
The log file suffix format for daily
, weekly
or monthly
rotation. Default is ‘%Y%m%d’.
Create an instance.
Matrix.new
is private; use Matrix.rows
, columns, [], etc… to create.
Vector.new
is private; use Vector[] or Vector.elements
to create.
Initializes the instance and yields itself if called with a block.
banner
Banner message.
width
Summary width.
indent
Summary indent.
Pushes a new List
.
Creates a buffer for pretty printing.
output
is an output target. If it is not specified, ” is assumed. It should have a << method which accepts the first argument obj
of PrettyPrint#text
, the first argument sep
of PrettyPrint#breakable
, the first argument newline
of PrettyPrint.new
, and the result of a given block for PrettyPrint.new
.
maxwidth
specifies maximum line length. If it is not specified, 79 is assumed. However actual outputs may overflow maxwidth
if long non-breakable texts are provided.
newline
is used for line breaks. “n” is used if it is not specified.
The block is used to generate spaces. {|width| ‘ ’ * width} is used if it is not given.
To construct a PStore
object, pass in the file path where you would like the data to be stored.
PStore
objects are always reentrant. But if thread_safe is set to true, then it will become thread-safe at the cost of a minor performance hit.
Create an RDoc
task with the given name. See the RDoc::Task
class overview for documentation.
Creates a new Resolv
using resolvers
.
Creates a new TempIO
that will be initialized to contain string
.
Creates a temporary file with permissions 0600 (= only readable and writable by the owner) and opens it with mode “w+”.
The basename
parameter is used to determine the name of the temporary file. You can either pass a String
or an Array
with 2 String
elements. In the former form, the temporary file’s base name will begin with the given string. In the latter form, the temporary file’s base name will begin with the array’s first element, and end with the second element. For example:
file = Tempfile.new('hello') file.path # => something like: "/tmp/hello2843-8392-92849382--0" # Use the Array form to enforce an extension in the filename: file = Tempfile.new(['hello', '.jpg']) file.path # => something like: "/tmp/hello2843-8392-92849382--0.jpg"
The temporary file will be placed in the directory as specified by the tmpdir
parameter. By default, this is Dir.tmpdir
.
file = Tempfile.new('hello', '/home/aisaka') file.path # => something like: "/home/aisaka/hello2843-8392-92849382--0"
You can also pass an options hash. Under the hood, Tempfile
creates the temporary file using File.open
. These options will be passed to File.open
. This is mostly useful for specifying encoding options, e.g.:
Tempfile.new('hello', '/home/aisaka', encoding: 'ascii-8bit') # You can also omit the 'tmpdir' parameter: Tempfile.new('hello', encoding: 'ascii-8bit')
Note: mode
keyword argument, as accepted by Tempfile
, can only be numeric, combination of the modes defined in File::Constants
.
If Tempfile.new
cannot find a unique filename within a limited number of tries, then it will raise an exception.
Creates a weak reference to orig
Raises an ArgumentError
if the given orig
is immutable, such as Symbol
, Integer
, or Float
.
Creates a new Proc
object, bound to the current context. Proc::new
may be called without a block only within a method with an attached block, in which case that block is converted to the Proc
object.
def proc_from Proc.new end proc = proc_from { "hello" } proc.call #=> "hello"
Creates a new thread executing the given block.
Any args
given to ::new
will be passed to the block:
arr = [] a, b, c = 1, 2, 3 Thread.new(a,b,c) { |d,e,f| arr << d << e << f }.join arr #=> [1, 2, 3]
A ThreadError
exception is raised if ::new
is called without a block.
If you’re going to subclass Thread
, be sure to call super in your initialize
method, otherwise a ThreadError
will be raised.
Creates a new PRNG using seed
to set the initial state. If seed
is omitted, the generator is initialized with Random.new_seed
.
See Random.srand
for more information on the use of seed values.
Creates a new Mutex
Creates a new condition variable instance.
Creates a new queue instance.
Creates a fixed-length queue with a maximum size of max
.
Returns a new TracePoint
object, not enabled by default.
Next, in order to activate the trace, you must use TracePoint#enable
trace = TracePoint.new(:call) do |tp| p [tp.lineno, tp.defined_class, tp.method_id, tp.event] end #=> #<TracePoint:disabled> trace.enable #=> false puts "Hello, TracePoint!" # ... # [48, IRB::Notifier::AbstractNotifier, :printf, :call] # ...
When you want to deactivate the trace, you must use TracePoint#disable
trace.disable
See Events at TracePoint
for possible events and more information.
A block must be given, otherwise an ArgumentError
is raised.
If the trace method isn’t included in the given events filter, a RuntimeError
is raised.
TracePoint.trace(:line) do |tp| p tp.raised_exception end #=> RuntimeError: 'raised_exception' not supported by this event
If the trace method is called outside block, a RuntimeError
is raised.
TracePoint.trace(:line) do |tp| $tp = tp end $tp.lineno #=> access from outside (RuntimeError)
Access from other threads is also forbidden.
Document-class: UncaughtThrowError
Raised when throw
is called with a tag which does not have corresponding catch
block.
throw "foo", "bar"
raises the exception:
UncaughtThrowError: uncaught throw "foo"
Use extend MonitorMixin
or include MonitorMixin
instead of this constructor. Have look at the examples above to understand how to use this module.