@foo ||= bar
becomes
@foo || @foo = bar
@foo += bar
becomes
@foo = @foo + bar
Dispatch enter and leave events for InstanceVariableAndWriteNode
nodes and continue walking the tree.
Dispatch enter and leave events for InstanceVariableOperatorWriteNode
nodes and continue walking the tree.
Dispatch enter and leave events for InstanceVariableOrWriteNode
nodes and continue walking the tree.
Inspect a InstanceVariableAndWriteNode
node.
Inspect a InstanceVariableOperatorWriteNode
node.
Inspect a InstanceVariableOrWriteNode
node.
Copy a InstanceVariableAndWriteNode
node
Copy a InstanceVariableOperatorWriteNode
node
Copy a InstanceVariableOrWriteNode
node
Returns the original source code as an array of lines.
Note that this is an API for ruby internal use, debugging, and research. Do not use this for any other purpose. The compatibility is not guaranteed.
Implement the hash pattern matching interface for Result
.
Ensures the root of chain
has a trusted certificate in trust_dir
and the digests of the two certificates match according to digester
Add a certificate to trusted certificate list.
Returns the index of the last element for which object == element
.
When argument object
is given but no block, returns the index of the last such element found:
a = [:foo, 'bar', 2, 'bar'] a.rindex('bar') # => 3
Returns nil
if no such object found.
When a block is given but no argument, calls the block with each successive element; returns the index of the last element for which the block returns a truthy value:
a = [:foo, 'bar', 2, 'bar'] a.rindex {|element| element == 'bar' } # => 3
Returns nil
if the block never returns a truthy value.
When neither an argument nor a block is given, returns a new Enumerator:
a = [:foo, 'bar', 2, 'bar'] e = a.rindex e # => #<Enumerator: [:foo, "bar", 2, "bar"]:rindex> e.each {|element| element == 'bar' } # => 3
Related: index
.
When no block given, returns a new Array
new_array
of size self.size
whose elements are Arrays.
Each nested array new_array[n]
is of size other_arrays.size+1
, and contains:
The nth element of self
.
The nth element of each of the other_arrays
.
If all other_arrays
and self
are the same size:
a = [:a0, :a1, :a2, :a3] b = [:b0, :b1, :b2, :b3] c = [:c0, :c1, :c2, :c3] d = a.zip(b, c) d # => [[:a0, :b0, :c0], [:a1, :b1, :c1], [:a2, :b2, :c2], [:a3, :b3, :c3]]
If any array in other_arrays
is smaller than self
, fills to self.size
with nil
:
a = [:a0, :a1, :a2, :a3] b = [:b0, :b1, :b2] c = [:c0, :c1] d = a.zip(b, c) d # => [[:a0, :b0, :c0], [:a1, :b1, :c1], [:a2, :b2, nil], [:a3, nil, nil]]
If any array in other_arrays
is larger than self
, its trailing elements are ignored:
a = [:a0, :a1, :a2, :a3] b = [:b0, :b1, :b2, :b3, :b4] c = [:c0, :c1, :c2, :c3, :c4, :c5] d = a.zip(b, c) d # => [[:a0, :b0, :c0], [:a1, :b1, :c1], [:a2, :b2, :c2], [:a3, :b3, :c3]]
If an argument is not an array, it extracts the values by calling each
:
a = [:a0, :a1, :a2, :a2] b = 1..4 c = a.zip(b) c # => [[:a0, 1], [:a1, 2], [:a2, 3], [:a2, 4]]
When a block is given, calls the block with each of the sub-arrays (formed as above); returns nil
:
a = [:a0, :a1, :a2, :a3] b = [:b0, :b1, :b2, :b3] c = [:c0, :c1, :c2, :c3] a.zip(b, c) {|sub_array| p sub_array} # => nil
Output:
[:a0, :b0, :c0] [:a1, :b1, :c1] [:a2, :b2, :c2] [:a3, :b3, :c3]
Transposes the rows and columns in an Array
of Arrays; the nested Arrays must all be the same size:
a = [[:a0, :a1], [:b0, :b1], [:c0, :c1]] a.transpose # => [[:a0, :b0, :c0], [:a1, :b1, :c1]]
Returns elements from self
; does not modify self
.
When no argument is given, returns the first element:
a = [:foo, 'bar', 2] a.first # => :foo a # => [:foo, "bar", 2]
If self
is empty, returns nil
.
When non-negative Integer
argument n
is given, returns the first n
elements in a new Array
:
a = [:foo, 'bar', 2] a.first(2) # => [:foo, "bar"]
If n >= array.size
, returns all elements:
a = [:foo, 'bar', 2] a.first(50) # => [:foo, "bar", 2]
If n == 0
returns an new empty Array
:
a = [:foo, 'bar', 2] a.first(0) # []
Related: last
.
Returns elements from self
; self
is not modified.
When no argument is given, returns the last element:
a = [:foo, 'bar', 2] a.last # => 2 a # => [:foo, "bar", 2]
If self
is empty, returns nil
.
When non-negative Integer
argument n
is given, returns the last n
elements in a new Array
:
a = [:foo, 'bar', 2] a.last(2) # => ["bar", 2]
If n >= array.size
, returns all elements:
a = [:foo, 'bar', 2] a.last(50) # => [:foo, "bar", 2]
If n == 0
, returns an new empty Array
:
a = [:foo, 'bar', 2] a.last(0) # []
Related: first
.