Update RubyGems software to the latest version.
Updates the TarHeader’s checksum
Returns true
if this gem is installable for the current platform.
Returns true
if this gem is installable for the current platform.
Returns true if this specification is installable on this platform.
Returns the element of self
specified by the given index
or nil
if there is no such element; index
must be an integer-convertible object.
For non-negative index
, returns the element of self
at offset index
:
a = [:foo, 'bar', 2] a.at(0) # => :foo a.at(2) # => 2 a.at(2.0) # => 2
For negative index
, counts backwards from the end of self
:
a.at(-2) # => "bar"
Related: Array#[]
; see also Methods for Fetching.
Adds to self
all elements from each array in other_arrays
; returns self
:
a = [0, 1] a.concat(['two', 'three'], [:four, :five], a) # => [0, 1, "two", "three", :four, :five, 0, 1]
Related: see Methods for Assigning.
Returns a new array that is a recursive flattening of self
to depth
levels of recursion; depth
must be an integer-convertible object or nil
. At each level of recursion:
Each element that is an array is “flattened” (that is, replaced by its individual array elements).
Each element that is not an array is unchanged (even if the element is an object that has instance method flatten
).
With non-negative integer argument depth
, flattens recursively through depth
levels:
a = [ 0, [ 1, [2, 3], 4 ], 5, {foo: 0}, Set.new([6, 7]) ] a # => [0, [1, [2, 3], 4], 5, {:foo=>0}, #<Set: {6, 7}>] a.flatten(0) # => [0, [1, [2, 3], 4], 5, {:foo=>0}, #<Set: {6, 7}>] a.flatten(1 ) # => [0, 1, [2, 3], 4, 5, {:foo=>0}, #<Set: {6, 7}>] a.flatten(1.1) # => [0, 1, [2, 3], 4, 5, {:foo=>0}, #<Set: {6, 7}>] a.flatten(2) # => [0, 1, 2, 3, 4, 5, {:foo=>0}, #<Set: {6, 7}>] a.flatten(3) # => [0, 1, 2, 3, 4, 5, {:foo=>0}, #<Set: {6, 7}>]
With nil
or negative depth
, flattens all levels.
a.flatten # => [0, 1, 2, 3, 4, 5, {:foo=>0}, #<Set: {6, 7}>] a.flatten(-1) # => [0, 1, 2, 3, 4, 5, {:foo=>0}, #<Set: {6, 7}>]
Related: Array#flatten!
; see also Methods for Converting.
Returns self
as a recursively flattening of self
to depth
levels of recursion; depth
must be an integer-convertible object, or nil
. At each level of recursion:
Each element that is an array is “flattened” (that is, replaced by its individual array elements).
Each element that is not an array is unchanged (even if the element is an object that has instance method flatten
).
Returns nil
if no elements were flattened.
With non-negative integer argument depth
, flattens recursively through depth
levels:
a = [ 0, [ 1, [2, 3], 4 ], 5, {foo: 0}, Set.new([6, 7]) ] a # => [0, [1, [2, 3], 4], 5, {:foo=>0}, #<Set: {6, 7}>] a.dup.flatten!(1) # => [0, 1, [2, 3], 4, 5, {:foo=>0}, #<Set: {6, 7}>] a.dup.flatten!(1.1) # => [0, 1, [2, 3], 4, 5, {:foo=>0}, #<Set: {6, 7}>] a.dup.flatten!(2) # => [0, 1, 2, 3, 4, 5, {:foo=>0}, #<Set: {6, 7}>] a.dup.flatten!(3) # => [0, 1, 2, 3, 4, 5, {:foo=>0}, #<Set: {6, 7}>]
With nil
or negative argument depth
, flattens all levels:
a.dup.flatten! # => [0, 1, 2, 3, 4, 5, {:foo=>0}, #<Set: {6, 7}>] a.dup.flatten!(-1) # => [0, 1, 2, 3, 4, 5, {:foo=>0}, #<Set: {6, 7}>]
Related: Array#flatten
; see also Methods for Assigning.
When a block and a positive integer-convertible object argument count
(0 < count <= self.size
) are given, calls the block with each combination of self
of size count
; returns self
:
a = %w[a b c] # => ["a", "b", "c"] a.combination(2) {|combination| p combination } # => ["a", "b", "c"]
Output:
["a", "b"] ["a", "c"] ["b", "c"]
The order of the yielded combinations is not guaranteed.
When count
is zero, calls the block once with a new empty array:
a.combination(0) {|combination| p combination } [].combination(0) {|combination| p combination }
Output:
[] []
When count
is negative or larger than self.size
and self
is non-empty, does not call the block:
a.combination(-1) {|combination| fail 'Cannot happen' } # => ["a", "b", "c"] a.combination(4) {|combination| fail 'Cannot happen' } # => ["a", "b", "c"]
With no block given, returns a new Enumerator
.
Related: Array#permutation
; see also 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.
Returns self
truncated (toward zero) to a precision of ndigits
decimal digits.
When ndigits
is negative, the returned value has at least ndigits.abs
trailing zeros:
555.truncate(-1) # => 550 555.truncate(-2) # => 500 -555.truncate(-2) # => -500
Returns self
when ndigits
is zero or positive.
555.truncate # => 555 555.truncate(50) # => 555
Related: Integer#round
.
Returns self
.
Returns 1
.
Returns the value as a rational. The optional argument eps
is always ignored.
Return the class or module refined by the receiver.
module M refine String do end end M.refinements[0].target # => String
Returns a new Complex object formed from the arguments, each of which must be an instance of Numeric
, or an instance of one of its subclasses: Complex, Float
, Integer
, Rational
; see Rectangular Coordinates:
Complex.rect(3) # => (3+0i) Complex.rect(3, Math::PI) # => (3+3.141592653589793i) Complex.rect(-3, -Math::PI) # => (-3-3.141592653589793i)
Complex.rectangular is an alias for Complex.rect.
Returns the array [self.real, self.imag]
:
Complex.rect(1, 2).rect # => [1, 2]
If self
was created with polar coordinates, the returned value is computed, and may be inexact:
Complex.polar(1.0, 1.0).rect # => [0.5403023058681398, 0.8414709848078965]
Complex#rectangular
is an alias for Complex#rect
.
Returns the conjugate of self
, Complex.rect(self.imag, self.real)
:
Complex.rect(1, 2).conj # => (1-2i)
Returns the Complex object created from the numerators of the real and imaginary parts of self
, after converting each part to the lowest common denominator of the two:
c = Complex.rect(Rational(2, 3), Rational(3, 4)) # => ((2/3)+(3/4)*i) c.numerator # => (8+9i)
In this example, the lowest common denominator of the two parts is 12; the two converted parts may be thought of as Rational(8, 12) and Rational(9, 12), whose numerators, respectively, are 8 and 9; so the returned value of c.numerator
is Complex.rect(8, 9)
.
Related: Complex#denominator
.
Returns the denominator of self
, which is the least common multiple of self.real.denominator
and self.imag.denominator
:
Complex.rect(Rational(1, 2), Rational(2, 3)).denominator # => 6
Note that n.denominator
of a non-rational numeric is 1
.
Related: Complex#numerator
.