Finds all gems that satisfy dep
Shows the context around code provided by “falling” indentation
Converts:
it "foo" do
into:
class OH def hello it "foo" do end end
Calls the block with each capitalized field name:
res = Net::HTTP.get_response(hostname, '/todos/1') res.each_capitalized_name do |key| p key if key.start_with?('C') end
Output:
"Content-Type" "Connection" "Cache-Control" "Cf-Cache-Status" "Cf-Ray"
The capitalization is system-dependent; see Case Mapping.
Returns an enumerator if no block is given.
foo.bar, = 1 ^^^^^^^
Returns all tokens for the input script regardless the receiver node. Returns nil
if keep_tokens
is not enabled when parse method is called.
root = RubyVM::AbstractSyntaxTree.parse("x = 1 + 2", keep_tokens: true) root.all_tokens # => [[0, :tIDENTIFIER, "x", [1, 0, 1, 1]], [1, :tSP, " ", [1, 1, 1, 2]], ...] root.children[-1].all_tokens # => [[0, :tIDENTIFIER, "x", [1, 0, 1, 1]], [1, :tSP, " ", [1, 1, 1, 2]], ...]
General callback for OpenSSL
verify
Return an array of APISpecification objects matching DependencyRequest req
.
Finds all specs matching req
in all sets.
Finds all git gems matching req
Return an array of IndexSpecification objects matching DependencyRequest req
.
Returns an array of IndexSpecification objects matching DependencyRequest req
.
Returns an Array
of IndexSpecification objects matching the DependencyRequest req
.
The find_all
method must be implemented. It returns all Resolver Specification objects matching the given DependencyRequest req
.
Returns an Array
of VendorSpecification objects matching the DependencyRequest req
.
Returns a new array formed from self
with elements rotated from one end to the other.
With non-negative numeric count
, rotates elements from the beginning to the end:
[0, 1, 2, 3].rotate(2) # => [2, 3, 0, 1] [0, 1, 2, 3].rotate(2.1) # => [2, 3, 0, 1]
If count
is large, uses count % array.size
as the count:
[0, 1, 2, 3].rotate(22) # => [2, 3, 0, 1]
With a count
of zero, rotates no elements:
[0, 1, 2, 3].rotate(0) # => [0, 1, 2, 3]
With negative numeric count
, rotates in the opposite direction, from the end to the beginning:
[0, 1, 2, 3].rotate(-1) # => [3, 0, 1, 2]
If count
is small (far from zero), uses count % array.size
as the count:
[0, 1, 2, 3].rotate(-21) # => [3, 0, 1, 2]
Related: see Methods for Fetching.
Rotates self
in place by moving elements from one end to the other; returns self
.
With non-negative numeric count
, rotates count
elements from the beginning to the end:
[0, 1, 2, 3].rotate!(2) # => [2, 3, 0, 1] [0, 1, 2, 3].rotate!(2.1) # => [2, 3, 0, 1]
If count
is large, uses count % array.size
as the count:
[0, 1, 2, 3].rotate!(21) # => [1, 2, 3, 0]
If count
is zero, rotates no elements:
[0, 1, 2, 3].rotate!(0) # => [0, 1, 2, 3]
With a negative numeric count
, rotates in the opposite direction, from end to beginning:
[0, 1, 2, 3].rotate!(-1) # => [3, 0, 1, 2]
If count
is small (far from zero), uses count % array.size
as the count:
[0, 1, 2, 3].rotate!(-21) # => [3, 0, 1, 2]
Related: see Methods for Assigning.
With a block given, calls the block with each element of self
; returns a new array whose elements are the return values from the block:
a = [:foo, 'bar', 2] a1 = a.map {|element| element.class } a1 # => [Symbol, String, Integer]
With no block given, returns a new Enumerator
.
Related: collect!
; see also Methods for Converting.
With a block given, calls the block with each element of self
and replaces the element with the block’s return value; returns self
:
a = [:foo, 'bar', 2] a.map! { |element| element.class } # => [Symbol, String, Integer]
With no block given, returns a new Enumerator
.
Related: collect
; see also Methods for Converting.
Replaces selected elements in self
; may add elements to self
; always returns self
(never a new array).
In brief:
# Non-negative start. ['a', 'b', 'c', 'd'].fill('-', 1, 2) # => ["a", "-", "-", "d"] ['a', 'b', 'c', 'd'].fill(1, 2) {|e| e.to_s } # => ["a", "1", "2", "d"] # Extends with specified values if necessary. ['a', 'b', 'c', 'd'].fill('-', 3, 2) # => ["a", "b", "c", "-", "-"] ['a', 'b', 'c', 'd'].fill(3, 2) {|e| e.to_s } # => ["a", "b", "c", "3", "4"] # Fills with nils if necessary. ['a', 'b', 'c', 'd'].fill('-', 6, 2) # => ["a", "b", "c", "d", nil, nil, "-", "-"] ['a', 'b', 'c', 'd'].fill(6, 2) {|e| e.to_s } # => ["a", "b", "c", "d", nil, nil, "6", "7"] # For negative start, counts backwards from the end. ['a', 'b', 'c', 'd'].fill('-', -3, 3) # => ["a", "-", "-", "-"] ['a', 'b', 'c', 'd'].fill(-3, 3) {|e| e.to_s } # => ["a", "1", "2", "3"] # Range. ['a', 'b', 'c', 'd'].fill('-', 1..2) # => ["a", "-", "-", "d"] ['a', 'b', 'c', 'd'].fill(1..2) {|e| e.to_s } # => ["a", "1", "2", "d"]
When arguments start
and count
are given, they select the elements of self
to be replaced; each must be an integer-convertible object (or nil
):
start
specifies the zero-based offset of the first element to be replaced; nil
means zero.
count
is the number of consecutive elements to be replaced; nil
means “all the rest.”
With argument object
given, that one object is used for all replacements:
o = Object.new # => #<Object:0x0000014e7bff7600> a = ['a', 'b', 'c', 'd'] # => ["a", "b", "c", "d"] a.fill(o, 1, 2) # => ["a", #<Object:0x0000014e7bff7600>, #<Object:0x0000014e7bff7600>, "d"]
With a block given, the block is called once for each element to be replaced; the value passed to the block is the index of the element to be replaced (not the element itself); the block’s return value replaces the element:
a = ['a', 'b', 'c', 'd'] # => ["a", "b", "c", "d"] a.fill(1, 2) {|element| element.to_s } # => ["a", "1", "2", "d"]
For arguments start
and count
:
If start
is non-negative, replaces count
elements beginning at offset start
:
['a', 'b', 'c', 'd'].fill('-', 0, 2) # => ["-", "-", "c", "d"] ['a', 'b', 'c', 'd'].fill('-', 1, 2) # => ["a", "-", "-", "d"] ['a', 'b', 'c', 'd'].fill('-', 2, 2) # => ["a", "b", "-", "-"] ['a', 'b', 'c', 'd'].fill(0, 2) {|e| e.to_s } # => ["0", "1", "c", "d"] ['a', 'b', 'c', 'd'].fill(1, 2) {|e| e.to_s } # => ["a", "1", "2", "d"] ['a', 'b', 'c', 'd'].fill(2, 2) {|e| e.to_s } # => ["a", "b", "2", "3"]
Extends self
if necessary:
['a', 'b', 'c', 'd'].fill('-', 3, 2) # => ["a", "b", "c", "-", "-"] ['a', 'b', 'c', 'd'].fill('-', 4, 2) # => ["a", "b", "c", "d", "-", "-"] ['a', 'b', 'c', 'd'].fill(3, 2) {|e| e.to_s } # => ["a", "b", "c", "3", "4"] ['a', 'b', 'c', 'd'].fill(4, 2) {|e| e.to_s } # => ["a", "b", "c", "d", "4", "5"]
Fills with nil
if necessary:
['a', 'b', 'c', 'd'].fill('-', 5, 2) # => ["a", "b", "c", "d", nil, "-", "-"] ['a', 'b', 'c', 'd'].fill('-', 6, 2) # => ["a", "b", "c", "d", nil, nil, "-", "-"] ['a', 'b', 'c', 'd'].fill(5, 2) {|e| e.to_s } # => ["a", "b", "c", "d", nil, "5", "6"] ['a', 'b', 'c', 'd'].fill(6, 2) {|e| e.to_s } # => ["a", "b", "c", "d", nil, nil, "6", "7"]
Does nothing if count
is non-positive:
['a', 'b', 'c', 'd'].fill('-', 2, 0) # => ["a", "b", "c", "d"] ['a', 'b', 'c', 'd'].fill('-', 2, -100) # => ["a", "b", "c", "d"] ['a', 'b', 'c', 'd'].fill('-', 6, -100) # => ["a", "b", "c", "d"] ['a', 'b', 'c', 'd'].fill(2, 0) {|e| fail 'Cannot happen' } # => ["a", "b", "c", "d"] ['a', 'b', 'c', 'd'].fill(2, -100) {|e| fail 'Cannot happen' } # => ["a", "b", "c", "d"] ['a', 'b', 'c', 'd'].fill(6, -100) {|e| fail 'Cannot happen' } # => ["a", "b", "c", "d"]
If start
is negative, counts backwards from the end of self
:
['a', 'b', 'c', 'd'].fill('-', -4, 3) # => ["-", "-", "-", "d"] ['a', 'b', 'c', 'd'].fill('-', -3, 3) # => ["a", "-", "-", "-"] ['a', 'b', 'c', 'd'].fill(-4, 3) {|e| e.to_s } # => ["0", "1", "2", "d"] ['a', 'b', 'c', 'd'].fill(-3, 3) {|e| e.to_s } # => ["a", "1", "2", "3"]
Extends self
if necessary:
['a', 'b', 'c', 'd'].fill('-', -2, 3) # => ["a", "b", "-", "-", "-"] ['a', 'b', 'c', 'd'].fill('-', -1, 3) # => ["a", "b", "c", "-", "-", "-"] ['a', 'b', 'c', 'd'].fill(-2, 3) {|e| e.to_s } # => ["a", "b", "2", "3", "4"] ['a', 'b', 'c', 'd'].fill(-1, 3) {|e| e.to_s } # => ["a", "b", "c", "3", "4", "5"]
Starts at the beginning of self
if start
is negative and out-of-range:
['a', 'b', 'c', 'd'].fill('-', -5, 2) # => ["-", "-", "c", "d"] ['a', 'b', 'c', 'd'].fill('-', -6, 2) # => ["-", "-", "c", "d"] ['a', 'b', 'c', 'd'].fill(-5, 2) {|e| e.to_s } # => ["0", "1", "c", "d"] ['a', 'b', 'c', 'd'].fill(-6, 2) {|e| e.to_s } # => ["0", "1", "c", "d"]
Does nothing if count
is non-positive:
['a', 'b', 'c', 'd'].fill('-', -2, 0) # => ["a", "b", "c", "d"] ['a', 'b', 'c', 'd'].fill('-', -2, -1) # => ["a", "b", "c", "d"] ['a', 'b', 'c', 'd'].fill(-2, 0) {|e| fail 'Cannot happen' } # => ["a", "b", "c", "d"] ['a', 'b', 'c', 'd'].fill(-2, -1) {|e| fail 'Cannot happen' } # => ["a", "b", "c", "d"]
When argument range
is given, it must be a Range
object whose members are numeric; its begin
and end
values determine the elements of self
to be replaced:
If both begin
and end
are positive, they specify the first and last elements to be replaced:
['a', 'b', 'c', 'd'].fill('-', 1..2) # => ["a", "-", "-", "d"] ['a', 'b', 'c', 'd'].fill(1..2) {|e| e.to_s } # => ["a", "1", "2", "d"]
If end
is smaller than begin
, replaces no elements:
['a', 'b', 'c', 'd'].fill('-', 2..1) # => ["a", "b", "c", "d"] ['a', 'b', 'c', 'd'].fill(2..1) {|e| e.to_s } # => ["a", "b", "c", "d"]
If either is negative (or both are negative), counts backwards from the end of self
:
['a', 'b', 'c', 'd'].fill('-', -3..2) # => ["a", "-", "-", "d"] ['a', 'b', 'c', 'd'].fill('-', 1..-2) # => ["a", "-", "-", "d"] ['a', 'b', 'c', 'd'].fill('-', -3..-2) # => ["a", "-", "-", "d"] ['a', 'b', 'c', 'd'].fill(-3..2) {|e| e.to_s } # => ["a", "1", "2", "d"] ['a', 'b', 'c', 'd'].fill(1..-2) {|e| e.to_s } # => ["a", "1", "2", "d"] ['a', 'b', 'c', 'd'].fill(-3..-2) {|e| e.to_s } # => ["a", "1", "2", "d"]
If the end
value is excluded (see Range#exclude_end?
), omits the last replacement:
['a', 'b', 'c', 'd'].fill('-', 1...2) # => ["a", "-", "c", "d"] ['a', 'b', 'c', 'd'].fill('-', 1...-2) # => ["a", "-", "c", "d"] ['a', 'b', 'c', 'd'].fill(1...2) {|e| e.to_s } # => ["a", "1", "c", "d"] ['a', 'b', 'c', 'd'].fill(1...-2) {|e| e.to_s } # => ["a", "1", "c", "d"]
If the range is endless (see Endless Ranges), replaces elements to the end of self
:
['a', 'b', 'c', 'd'].fill('-', 1..) # => ["a", "-", "-", "-"] ['a', 'b', 'c', 'd'].fill(1..) {|e| e.to_s } # => ["a", "1", "2", "3"]
If the range is beginless (see Beginless Ranges), replaces elements from the beginning of self
:
['a', 'b', 'c', 'd'].fill('-', ..2) # => ["-", "-", "-", "d"] ['a', 'b', 'c', 'd'].fill(..2) {|e| e.to_s } # => ["0", "1", "2", "d"]
Related: see Methods for Assigning.
Iterates over permutations of the elements of self
; the order of permutations is indeterminate.
With a block and an in-range positive integer argument count
(0 < count <= self.size
) given, calls the block with each permutation of self
of size count
; returns self
:
a = [0, 1, 2] perms = [] a.permutation(1) {|perm| perms.push(perm) } perms # => [[0], [1], [2]] perms = [] a.permutation(2) {|perm| perms.push(perm) } perms # => [[0, 1], [0, 2], [1, 0], [1, 2], [2, 0], [2, 1]] perms = [] a.permutation(3) {|perm| perms.push(perm) } perms # => [[0, 1, 2], [0, 2, 1], [1, 0, 2], [1, 2, 0], [2, 0, 1], [2, 1, 0]]
When count
is zero, calls the block once with a new empty array:
perms = [] a.permutation(0) {|perm| perms.push(perm) } perms # => [[]]
When count
is out of range (negative or larger than self.size
), does not call the block:
a.permutation(-1) {|permutation| fail 'Cannot happen' } a.permutation(4) {|permutation| fail 'Cannot happen' }
With no block given, returns a new Enumerator
.
Related: Methods for Iterating.
Returns a new array containing the first count
element of self
(as available); count
must be a non-negative numeric; does not modify self
:
a = ['a', 'b', 'c', 'd'] a.take(2) # => ["a", "b"] a.take(2.1) # => ["a", "b"] a.take(50) # => ["a", "b", "c", "d"] a.take(0) # => []
Related: see Methods for Fetching.