Returns the current execution stack—an array containing backtrace location objects.
See Thread::Backtrace::Location
for more information.
The optional start parameter determines the number of initial stack entries to omit from the top of the stack.
A second optional length
parameter can be used to limit how many entries are returned from the stack.
Returns nil
if start is greater than the size of current execution stack.
Optionally you can pass a range, which will return an array containing the entries within the specified range.
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
.
Enters exclusive section and executes the block. Leaves the exclusive section automatically when the block exits. See example under MonitorMixin
.
Returns the source file origin from the given object
.
See ::trace_object_allocations
for more information and examples.
Convert the given options into a serialized options string.
Computes and returns or yields all combinations of elements from all the Arrays, including both self
and other_arrays
:
The number of combinations is the product of the sizes of all the arrays, including both self
and other_arrays
.
The order of the returned combinations is indeterminate.
When no block is given, returns the combinations as an Array
of Arrays:
a = [0, 1, 2] a1 = [3, 4] a2 = [5, 6] p = a.product(a1) p.size # => 6 # a.size * a1.size p # => [[0, 3], [0, 4], [1, 3], [1, 4], [2, 3], [2, 4]] p = a.product(a1, a2) p.size # => 12 # a.size * a1.size * a2.size p # => [[0, 3, 5], [0, 3, 6], [0, 4, 5], [0, 4, 6], [1, 3, 5], [1, 3, 6], [1, 4, 5], [1, 4, 6], [2, 3, 5], [2, 3, 6], [2, 4, 5], [2, 4, 6]]
If any argument is an empty Array
, returns an empty Array
.
If no argument is given, returns an Array
of 1-element Arrays, each containing an element of self
:
a.product # => [[0], [1], [2]]
When a block is given, yields each combination as an Array
; returns self
:
a.product(a1) {|combination| p combination }
Output:
[0, 3] [0, 4] [1, 3] [1, 4] [2, 3] [2, 4]
If any argument is an empty Array
, does not call the block:
a.product(a1, a2, []) {|combination| fail 'Cannot happen' }
If no argument is given, yields each element of self
as a 1-element Array
:
a.product {|combination| p combination }
Output:
[0] [1] [2]
Generates a new enumerator object that generates a Cartesian product of given enumerable objects. This is equivalent to Enumerator::Product.new
.
e = Enumerator.product(1..3, [4, 5]) e.to_a #=> [[1, 4], [1, 5], [2, 4], [2, 5], [3, 4], [3, 5]] e.size #=> 6
When a block is given, calls the block with each N-element array generated and returns nil
.
Create a new AlternationPatternNode
node
Create a new OptionalKeywordParameterNode
node
Create a new OptionalParameterNode
node
Create a new PostExecutionNode
node
Create a new PreExecutionNode
node
Create a new RationalNode
node
Invoked as a callback whenever a singleton method is undefined in the receiver.
module Chatty def Chatty.singleton_method_undefined(id) puts "Undefining #{id.id2name}" end def Chatty.one() end class << self undef_method(:one) end end
produces:
Undefining one
Returns a new lazy enumerator with the concatenated results of running block
once for every element in the lazy enumerator.
["foo", "bar"].lazy.flat_map {|i| i.each_char.lazy}.force #=> ["f", "o", "o", "b", "a", "r"]
A value x
returned by block
is decomposed if either of the following conditions is true:
x
responds to both each and force, which means that x
is a lazy enumerator.
x
is an array or responds to to_ary.
Otherwise, x
is contained as-is in the return value.
[{a:1}, {b:2}].lazy.flat_map {|i| i}.force #=> [{:a=>1}, {:b=>2}]
Returns the destination encoding as an encoding object.
Returns the destination encoding as an encoding object.
Returns the destination encoding as an Encoding
object.
Returns a data represents the current console mode.
You must require ‘io/console’ to use this method.