Returns a Hash
(not a DBM
database) created by using each value in the database as a key, with the corresponding key as its value.
Note that all values in the hash will be Strings, but the keys will be actual objects.
If a block is provided, returns a new array containing [key, value] pairs for which the block returns true.
Otherwise, same as values_at
Returns true
if this process is stopped, and if the corresponding wait call had the Process::WUNTRACED flag set, false
otherwise.
Returns the number of the signal that caused the process to stop, or nil
if the process is not stopped.
Returns the number of the signal that caused the process to terminate or nil
if the process was not terminated by an uncaught signal.
Called when the current thread exits. The scheduler is expected to implement this method in order to allow all waiting fibers to finalize their execution.
The suggested pattern is to implement the main event loop in the close
method.
Implementation of the Fiber.schedule
. The method is expected to immediately run the given block of code in a separate non-blocking fiber, and to return that Fiber
.
Minimal suggested implementation is:
def fiber(&block) fiber = Fiber.new(blocking: false, &block) fiber.resume fiber end
Obtains a lock, runs the block, and releases the lock when the block completes. See the example under Thread::Mutex
.
Closes the queue. A closed queue cannot be re-opened.
After the call to close completes, the following are true:
closed?
will return true
close
will be ignored.
calling enq/push/<< will raise a ClosedQueueError
.
when empty?
is false, calling deq/pop/shift will return an object from the queue as usual.
when empty?
is true, deq(false) will not suspend the thread and will return nil. deq(true) will raise a ThreadError
.
ClosedQueueError
is inherited from StopIteration
, so that you can break loop block.
Example:
q = Thread::Queue.new Thread.new{ while e = q.deq # wait for nil to break loop # ... end } q.close
Returns true
if the queue is closed.
Returns true
if the queue is empty.
Removes all objects from the queue.
Retrieves data from the queue.
If the queue is empty, the calling thread is suspended until data is pushed onto the queue. If non_block
is true, the thread isn’t suspended, and ThreadError
is raised.
If timeout
seconds have passed and no data is available nil
is returned. If timeout
is 0
it returns immediately.
Similar to Thread::Queue#close
.
The difference is behavior with waiting enqueuing threads.
If there are waiting enqueuing threads, they are interrupted by raising ClosedQueueError(‘queue closed’).
Returns true
if the queue is empty.
Removes all objects from the queue.
Retrieves data from the queue.
If the queue is empty, the calling thread is suspended until data is pushed onto the queue. If non_block
is true, the thread isn’t suspended, and ThreadError
is raised.
If timeout
seconds have passed and no data is available nil
is returned. If timeout
is 0
it returns immediately.
Returns true
if key
is a key in self
, otherwise false
.
Removes all map entries; returns self
.
Returns URL-escaped string following RFC 3986.
Returns URL-unescaped string following RFC 3986.
URL-encode a string following RFC 3986 Space characters (+“ ”+) are encoded with (+“%20”+)
url_encoded_string = CGI.escapeURIComponent("'Stop!' said Fred") # => "%27Stop%21%27%20said%20Fred"