Returns every spec that has the given full_name
Returns the modulo after division of float
by other
.
6543.21.modulo(137) #=> 104.21000000000004 6543.21.modulo(137.24) #=> 92.92999999999961
Returns garbage collector generation for the given object
.
class B include ObjectSpace def foo trace_object_allocations do obj = Object.new p "Generation is #{allocation_generation(obj)}" end end end B.new.foo #=> "Generation is 3"
See ::trace_object_allocations
for more information and examples.
Fiber
scheduler, set in the current thread with Fiber.set_scheduler
. If the scheduler is nil
(which is the default), non-blocking fibers behavior is the same as blocking. (see “Non-blocking fibers” section in class docs for details about the scheduler concept).
The method is expected to immediately run the provided block of code in a separate non-blocking fiber.
puts "Go to sleep!" Fiber.set_scheduler(MyScheduler.new) Fiber.schedule do puts "Going to sleep" sleep(1) puts "I slept well" end puts "Wakey-wakey, sleepyhead"
Assuming MyScheduler is properly implemented, this program will produce:
Go to sleep! Going to sleep Wakey-wakey, sleepyhead ...1 sec pause here... I slept well
…e.g. on the first blocking operation inside the Fiber
(sleep(1)
), the control is yielded at the outside code (main fiber), and at the end of the execution, the scheduler takes care of properly resuming all the blocked fibers.
Note that the behavior described above is how the method is expected to behave, actual behavior is up to the current scheduler’s implementation of Fiber::SchedulerInterface#fiber
method. Ruby doesn’t enforce this method to behave in any particular way.
If the scheduler is not set, the method raises RuntimeError (No scheduler is available!)
.
Returns a new Array containing each element found both in self
and in all of the given Arrays other_arrays
; duplicates are omitted; items are compared using eql?
:
[0, 1, 2, 3].intersection([0, 1, 2], [0, 1, 3]) # => [0, 1] [0, 0, 1, 1, 2, 3].intersection([0, 1, 2], [0, 1, 3]) # => [0, 1]
Preserves order from self
:
[0, 1, 2].intersection([2, 1, 0]) # => [0, 1, 2]
Returns a copy of self
if no arguments given.
Related: Array#&
.
Searches sep or pattern (regexp) in the string and returns the part before it, the match, and the part after it. If it is not found, returns two empty strings and str.
"hello".partition("l") #=> ["he", "l", "lo"] "hello".partition("x") #=> ["hello", "", ""] "hello".partition(/.l/) #=> ["h", "el", "lo"]
Searches sep or pattern (regexp) in the string from the end of the string, and returns the part before it, the match, and the part after it. If it is not found, returns two empty strings and str.
"hello".rpartition("l") #=> ["hel", "l", "o"] "hello".rpartition("x") #=> ["", "", "hello"] "hello".rpartition(/.l/) #=> ["he", "ll", "o"]
The match from the end means starting at the possible last position, not the last of longest matches.
"hello".rpartition(/l+/) #=> ["hel", "l", "o"]
To partition at the last longest match, needs to combine with negative lookbehind.
"hello".rpartition(/(?<!l)l+/) #=> ["he", "ll", "o"]
Or String#partition
with negative lookforward.
"hello".partition(/l+(?!.*l)/) #=> ["he", "ll", "o"]
Opens a new transaction for the data store. Code executed inside a block passed to this method may read and write data to and from the data store file.
At the end of the block, changes are committed to the data store automatically. You may exit the transaction early with a call to either PStore#commit
or PStore#abort
. See those methods for details about how changes are handled. Raising an uncaught Exception
in the block is equivalent to calling PStore#abort
.
If read_only is set to true
, you will only be allowed to read from the data store during the transaction and any attempts to change the data will raise a PStore::Error
.
Note that PStore
does not support nested transactions.
Returns two arrays, the first containing the elements of enum for which the block evaluates to true, the second containing the rest.
If no block is given, an enumerator is returned instead.
(1..6).partition { |v| v.even? } #=> [[2, 4, 6], [1, 3, 5]]
The standard configuration object for gems.
Use the given configuration object (which implements the ConfigFile
protocol) as the standard configuration object.
Returns the fractional part of the second.
DateTime.new(2001,2,3,4,5,6.5).sec_fraction #=> (1/2)
Compiled instruction sequence represented by a RubyVM::InstructionSequence
instance on the :script_compiled
event.
Note that this method is MRI specific.
Raises a VersionConflict
error, or any underlying error, if there is no current state @return [void]
Specifies a Proc
object proc
to determine if a character in the user’s input is escaped. It should take the user’s input and the index of the character in question as input, and return a boolean (true if the specified character is escaped).
Readline
will only call this proc with characters specified in completer_quote_characters
, to discover if they indicate the end of a quoted argument, or characters specified in completer_word_break_characters
, to discover if they indicate a break between arguments.
If completer_quote_characters
is not set, or if the user input doesn’t contain one of the completer_quote_characters
or a ++ character, Readline
will not attempt to use this proc at all.
Raises ArgumentError
if proc
does not respond to the call method.
Returns the quoting detection Proc
object.
Verify compaction reference consistency.
This method is implementation specific. During compaction, objects that were moved are replaced with T_MOVED objects. No object should have a reference to a T_MOVED object after compaction.
This function doubles the heap to ensure room to move all objects, compacts the heap to make sure everything moves, updates all references, then performs a full GC
. If any object contains a reference to a T_MOVED object, that object should be pushed on the mark stack, and will make a SEGV.