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 new set containing the elements of the given enumerable object.
If a block is given, the elements of enum are preprocessed by the given block.
Set.new([1, 2]) #=> #<Set: {1, 2}> Set.new([1, 2, 1]) #=> #<Set: {1, 2}> Set.new([1, 'c', :s]) #=> #<Set: {1, "c", :s}> Set.new(1..5) #=> #<Set: {1, 2, 3, 4, 5}> Set.new([1, 2, 3]) { |x| x * x } #=> #<Set: {1, 4, 9}>
Creates a Shell
object which current directory is set to the process current directory, unless otherwise specified by the pwd
argument.
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
. When $SAFE > 0 and the given tmpdir
is tainted, it uses ‘/tmp’ as the temporary directory. Please note that ENV
values are tainted by default, and Dir.tmpdir
‘s return value might come from environment variables (e.g. $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 ThreadsWait
object, specifying the threads to wait on. Non-blocking.
Creates a ThreadsWait
object, specifying the threads to wait on. Non-blocking.
Creates a weak reference to orig
Raises an ArgumentError
if the given orig
is immutable, such as Symbol
, Integer
, or Float
.
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.
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
.
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.
This string is put at the end of a line that holds a JSON
array.