Returns additional info.
Returns match and captures at the given indexes
, which may include any mixture of:
Integers.
Ranges.
Names (strings and symbols).
Examples:
m = /(.)(.)(\d+)(\d)/.match("THX1138: The Movie") # => #<MatchData "HX1138" 1:"H" 2:"X" 3:"113" 4:"8"> m.values_at(0, 2, -2) # => ["HX1138", "X", "113"] m.values_at(1..2, -1) # => ["H", "X", "8"] m = /(?<a>\d+) *(?<op>[+\-*\/]) *(?<b>\d+)/.match("1 + 2") # => #<MatchData "1 + 2" a:"1" op:"+" b:"2"> m.values_at(0, 1..2, :a, :b, :op) # => ["1 + 2", "1", "+", "1", "2", "+"]
This is similar to breakable
except the decision to break or not is determined individually.
Two fill_breakable
under a group may cause 4 results: (break,break), (break,non-break), (non-break,break), (non-break,non-break). This is different to breakable
because two breakable
under a group may cause 2 results: (break,break), (non-break,non-break).
The text sep
is inserted if a line is not broken at this point.
If sep
is not specified, “ ” is used.
If width
is not specified, sep.length
is used. You will have to specify this when sep
is a multibyte character, for example.
Load the given PStore
file. If read_only
is true, the unmarshalled Hash
will be returned. If read_only
is false, a 3-tuple will be returned: the unmarshalled Hash
, a checksum of the data, and the size of the data.
Returns true if the referenced object is still alive.
Returns the exit value associated with this LocalJumpError
.
Returns the original name of the method.
class C def foo; end alias bar foo end C.instance_method(:bar).original_name # => :foo
Returns the original name of the method.
class C def foo; end alias bar foo end C.instance_method(:bar).original_name # => :foo
Return value from :return
, :c_return
, and :b_return
event
Compiled source code (String
) on *eval methods on the :script_compiled
event. If loaded from a file, it will return nil.
Returns an array of the names of global variables. This includes special regexp global variables such as $~
and $+
, but does not include the numbered regexp global variables ($1
, $2
, etc.).
global_variables.grep /std/ #=> [:$stdin, :$stdout, :$stderr]
Returns the names of the current local variables.
fred = 1 for i in 1..10 # ... end local_variables #=> [:fred, :i]
Returns an array of flattened objects returned by the block.
With a block given, calls the block with successive elements; returns a flattened array of objects returned by the block:
[0, 1, 2, 3].flat_map {|element| -element } # => [0, -1, -2, -3] [0, 1, 2, 3].flat_map {|element| [element, -element] } # => [0, 0, 1, -1, 2, -2, 3, -3] [[0, 1], [2, 3]].flat_map {|e| e + [100] } # => [0, 1, 100, 2, 3, 100] {foo: 0, bar: 1, baz: 2}.flat_map {|key, value| [key, value] } # => [:foo, 0, :bar, 1, :baz, 2]
With no block given, returns an Enumerator
.
Alias: collect_concat
.
Calls the block with successive elements as long as the block returns a truthy value; returns an array of all elements up to that point:
(1..4).take_while{|i| i < 3 } # => [1, 2] h = {foo: 0, bar: 1, baz: 2} h.take_while{|element| key, value = *element; value < 2 } # => [[:foo, 0], [:bar, 1]]
With no block given, returns an Enumerator
.
Initializes the MonitorMixin
after being included in a class or when an object has been extended with the MonitorMixin
Adds aProc as a finalizer, to be called after obj was destroyed. The object ID of the obj will be passed as an argument to aProc. If aProc is a lambda or method, make sure it can be called with a single argument.
The return value is an array [0, aProc]
.
The two recommended patterns are to either create the finaliser proc in a non-instance method where it can safely capture the needed state, or to use a custom callable object that stores the needed state explicitly as instance variables.
class Foo def initialize(data_needed_for_finalization) ObjectSpace.define_finalizer(self, self.class.create_finalizer(data_needed_for_finalization)) end def self.create_finalizer(data_needed_for_finalization) proc { puts "finalizing #{data_needed_for_finalization}" } end end class Bar class Remover def initialize(data_needed_for_finalization) @data_needed_for_finalization = data_needed_for_finalization end def call(id) puts "finalizing #{@data_needed_for_finalization}" end end def initialize(data_needed_for_finalization) ObjectSpace.define_finalizer(self, Remover.new(data_needed_for_finalization)) end end
Note that if your finalizer references the object to be finalized it will never be run on GC
, although it will still be run at exit. You will get a warning if you capture the object to be finalized as the receiver of the finalizer.
class CapturesSelf def initialize(name) ObjectSpace.define_finalizer(self, proc { # this finalizer will only be run on exit puts "finalizing #{name}" }) end end
Also note that finalization can be unpredictable and is never guaranteed to be run except on exit.
Removes all finalizers for obj.
Alias of GC.start
Alias of GC.start
Returns the table for calculating CRC checksum as an array.
Returns true
if the named file is readable by the real user and group id of this process. See access(3).
Note that some OS-level security features may cause this to return true even though the file is not readable by the real user/group.
If file_name is writable by others, returns an integer representing the file permission bits of file_name. Returns nil
otherwise. The meaning of the bits is platform dependent; on Unix systems, see stat(2)
.
file_name can be an IO
object.
File.world_writable?("/tmp") #=> 511 m = File.world_writable?("/tmp") sprintf("%o", m) #=> "777"
Alias of GC.start
Returns information for heaps in the GC.
If the first optional argument, heap_name
, is passed in and not nil
, it returns a Hash
containing information about the particular heap. Otherwise, it will return a Hash
with heap names as keys and a Hash
containing information about the heap as values.
If the second optional argument, hash_or_key
, is given as Hash
, it will be overwritten and returned. This is intended to avoid the probe effect.
If both optional arguments are passed in and the second optional argument is a symbol, it will return a Numeric
of the value for the particular heap.
On CRuby, heap_name
is of the type Integer
but may be of type String
on other implementations.
The contents of the hash are implementation specific and may change in the future without notice.
If the optional argument, hash, is given, it is overwritten and returned.
This method is only expected to work on CRuby.
The hash includes the following keys about the internal information in the GC:
The slot size of the heap in bytes.
The number of pages that can be allocated without triggering a new garbage collection cycle.
The number of pages in the eden heap.
The total number of slots in all of the pages in the eden heap.
The number of pages in the tomb heap. The tomb heap only contains pages that do not have any live objects.
The total number of slots in all of the pages in the tomb heap.
The total number of pages that have been allocated in the heap.
The total number of pages that have been freed and released back to the system in the heap.
The number of times major garbage collection cycles this heap has forced to start due to running out of free slots.
The number of times this heap has forced incremental marking to complete due to running out of pooled slots.