Returns the path to the trusted certificate
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.
Inserts the given objects
as elements of self
; returns self
.
When index
is non-negative, inserts objects
before the element at offset index
:
a = ['a', 'b', 'c'] # => ["a", "b", "c"] a.insert(1, :x, :y, :z) # => ["a", :x, :y, :z, "b", "c"]
Extends the array if index
is beyond the array (index >= self.size
):
a = ['a', 'b', 'c'] # => ["a", "b", "c"] a.insert(5, :x, :y, :z) # => ["a", "b", "c", nil, nil, :x, :y, :z]
When index
is negative, inserts objects
after the element at offset index + self.size
:
a = ['a', 'b', 'c'] # => ["a", "b", "c"] a.insert(-2, :x, :y, :z) # => ["a", "b", :x, :y, :z, "c"]
With no objects
given, does nothing:
a = ['a', 'b', 'c'] # => ["a", "b", "c"] a.insert(1) # => ["a", "b", "c"] a.insert(50) # => ["a", "b", "c"] a.insert(-50) # => ["a", "b", "c"]
Raises IndexError
if objects
are given and index
is negative and out of range.
Related: see Methods for Assigning.
Returns a new array containing the elements of self
, sorted.
With no block given, compares elements using operator #<=>
(see Object#<=>
):
[0, 2, 3, 1].sort # => [0, 1, 2, 3]
With a block given, calls the block with each combination of pairs of elements from self
; for each pair a
and b
, the block should return a numeric:
Negative when b
is to follow a
.
Zero when a
and b
are equivalent.
Positive when a
is to follow b
.
Example:
a = [3, 2, 0, 1] a.sort {|a, b| a <=> b } # => [0, 1, 2, 3] a.sort {|a, b| b <=> a } # => [3, 2, 1, 0]
When the block returns zero, the order for a
and b
is indeterminate, and may be unstable.
Related: see Methods for Fetching.
Like Array#sort
, but returns self
with its elements sorted in place.
Related: see Methods for Assigning.
Removes all elements from self
; returns self
:
a = [:foo, 'bar', 2] a.clear # => []
Related: see Methods for Deleting.
Returns a new array containing only the non-nil
elements from self
; element order is preserved:
a = [nil, 0, nil, false, nil, '', nil, [], nil, {}] a.compact # => [0, false, "", [], {}]
Related: Array#compact!
; see also Methods for Deleting.
Removes all nil
elements from self
; Returns self
if any elements are removed, nil
otherwise:
a = [nil, 0, nil, false, nil, '', nil, [], nil, {}] a.compact! # => [0, false, "", [], {}] a # => [0, false, "", [], {}] a.compact! # => nil
Related: Array#compact
; see also Methods for Deleting.
Returns the element from self
found by a binary search, or nil
if the search found no suitable element.
See Binary Searching.
Related: see Methods for Fetching.
Returns true
if no element of self
meets a given criterion, false
otherwise.
With no block given and no argument, returns true
if self
has no truthy elements, false
otherwise:
[nil, false].none? # => true [nil, 0, false].none? # => false [].none? # => true
With argument object
given, returns false
if for any element element
, object === element
; true
otherwise:
['food', 'drink'].none?(/bar/) # => true ['food', 'drink'].none?(/foo/) # => false [].none?(/foo/) # => true [0, 1, 2].none?(3) # => true [0, 1, 2].none?(1) # => false
With a block given, calls the block with each element in self
; returns true
if the block returns no truthy value, false
otherwise:
[0, 1, 2].none? {|element| element > 3 } # => true [0, 1, 2].none? {|element| element > 1 } # => false
Related: see Methods for Querying.
Returns true
if exactly one element of self
meets a given criterion.
With no block given and no argument, returns true
if self
has exactly one truthy element, false
otherwise:
[nil, 0].one? # => true [0, 0].one? # => false [nil, nil].one? # => false [].one? # => false
With a block given, calls the block with each element in self
; returns true
if the block a truthy value for exactly one element, false
otherwise:
[0, 1, 2].one? {|element| element > 0 } # => false [0, 1, 2].one? {|element| element > 1 } # => true [0, 1, 2].one? {|element| element > 2 } # => false
With argument object
given, returns true
if for exactly one element element
, object === element
; false
otherwise:
[0, 1, 2].one?(0) # => true [0, 0, 1].one?(0) # => false [1, 1, 2].one?(0) # => false ['food', 'drink'].one?(/bar/) # => false ['food', 'drink'].one?(/foo/) # => true [].one?(/foo/) # => false
Related: see Methods for Querying.
Formats each element in self
into a binary string; returns that string. See Packed Data.
Returns the integer square root of the non-negative integer n
, which is the largest non-negative integer less than or equal to the square root of numeric
.
Integer.sqrt(0) # => 0 Integer.sqrt(1) # => 1 Integer.sqrt(24) # => 4 Integer.sqrt(25) # => 5 Integer.sqrt(10**400) # => 10**200
If numeric
is not an Integer, it is converted to an Integer:
Integer.sqrt(Complex(4, 0)) # => 2 Integer.sqrt(Rational(4, 1)) # => 2 Integer.sqrt(4.0) # => 2 Integer.sqrt(3.14159) # => 1
This method is equivalent to Math.sqrt(numeric).floor
, except that the result of the latter code may differ from the true value due to the limited precision of floating point arithmetic.
Integer.sqrt(10**46) # => 100000000000000000000000 Math.sqrt(10**46).floor # => 99999999999999991611392
Raises an exception if numeric
is negative.
Returns true
if all bits that are set (=1) in mask
are also set in self
; returns false
otherwise.
Example values:
0b1010101 self 0b1010100 mask 0b1010100 self & mask true self.allbits?(mask) 0b1010100 self 0b1010101 mask 0b1010100 self & mask false self.allbits?(mask)
Related: Integer#anybits?
, Integer#nobits?
.
Returns true
if any bit that is set (=1) in mask
is also set in self
; returns false
otherwise.
Example values:
0b10000010 self 0b11111111 mask 0b10000010 self & mask true self.anybits?(mask) 0b00000000 self 0b11111111 mask 0b00000000 self & mask false self.anybits?(mask)
Related: Integer#allbits?
, Integer#nobits?
.
Returns true
if no bit that is set (=1) in mask
is also set in self
; returns false
otherwise.
Example values:
0b11110000 self 0b00001111 mask 0b00000000 self & mask true self.nobits?(mask) 0b00000001 self 0b11111111 mask 0b00000001 self & mask false self.nobits?(mask)
Related: Integer#allbits?
, Integer#anybits?
.
Returns an array of integers representing the base
-radix digits of self
; the first element of the array represents the least significant digit:
12345.digits # => [5, 4, 3, 2, 1] 12345.digits(7) # => [4, 6, 6, 0, 5] 12345.digits(100) # => [45, 23, 1]
Raises an exception if self
is negative or base
is less than 2.
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 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
. Argument arg
is given in radians; see Polar Coordinates:
Complex.polar(3) # => (3+0i) Complex.polar(3, 2.0) # => (-1.2484405096414273+2.727892280477045i) Complex.polar(-3, -2.0) # => (1.2484405096414273+2.727892280477045i)
Returns the imaginary value for self
:
Complex.rect(7).imag # => 0 Complex.rect(9, -4).imag # => -4
If self
was created with polar coordinates, the returned value is computed, and may be inexact:
Complex.polar(1, Math::PI/4).imag # => 0.7071067811865476 # Square root of 2.