Loads the given certificate_file
Returns a new Array
containing only those elements from self
that are not found in any of the Arrays other_arrays
; items are compared using eql?
; order from self
is preserved:
[0, 1, 1, 2, 1, 1, 3, 1, 1].difference([1]) # => [0, 2, 3] [0, 1, 2, 3].difference([3, 0], [1, 3]) # => [2] [0, 1, 2].difference([4]) # => [0, 1, 2]
Returns a copy of self
if no arguments given.
Related: Array#-
.
Returns a new Array
containing each element found both in self
and in all of the given Arrays other_arrays
; duplicates are omitted; items are compared using eql?
(items must also implement hash
correctly):
[0, 1, 2, 3].intersection([0, 1, 2], [0, 1, 3]) # => [0, 1] [0, 0, 1, 1, 2, 3].intersection([0, 1, 2], [0, 1, 3]) # => [0, 1]
Preserves order from self
:
[0, 1, 2].intersection([2, 1, 0]) # => [0, 1, 2]
Returns a copy of self
if no arguments given.
Related: Array#&
.
Returns true
if the array and other_ary
have at least one element in common, otherwise returns false
:
a = [ 1, 2, 3 ] b = [ 3, 4, 5 ] c = [ 5, 6, 7 ] a.intersect?(b) #=> true a.intersect?(c) #=> false
Array
elements are compared using eql?
(items must also implement hash
correctly).
Inserts given objects
before or after the element at Integer
index offset
; returns self
.
When index
is non-negative, inserts all given objects
before the element at offset index
:
a = [:foo, 'bar', 2] a.insert(1, :bat, :bam) # => [:foo, :bat, :bam, "bar", 2]
Extends the array if index
is beyond the array (index >= self.size
):
a = [:foo, 'bar', 2] a.insert(5, :bat, :bam) a # => [:foo, "bar", 2, nil, nil, :bat, :bam]
Does nothing if no objects given:
a = [:foo, 'bar', 2] a.insert(1) a.insert(50) a.insert(-50) a # => [:foo, "bar", 2]
When index
is negative, inserts all given objects
after the element at offset index+self.size
:
a = [:foo, 'bar', 2] a.insert(-2, :bat, :bam) a # => [:foo, "bar", :bat, :bam, 2]
Returns a new Array
with the elements of self
in reverse order:
a = ['foo', 'bar', 'two'] a1 = a.reverse a1 # => ["two", "bar", "foo"]
Reverses self
in place:
a = ['foo', 'bar', 'two'] a.reverse! # => ["two", "bar", "foo"]
Calls the block, if given, with each element of self
; returns a new Array
containing those elements of self
for which the block returns a truthy value:
a = [:foo, 'bar', 2, :bam] a1 = a.select {|element| element.to_s.start_with?('b') } a1 # => ["bar", :bam]
Returns a new Enumerator
if no block given:
a = [:foo, 'bar', 2, :bam] a.select # => #<Enumerator: [:foo, "bar", 2, :bam]:select>
Calls the block, if given with each element of self
; removes from self
those elements for which the block returns false
or nil
.
Returns self
if any elements were removed:
a = [:foo, 'bar', 2, :bam] a.select! {|element| element.to_s.start_with?('b') } # => ["bar", :bam]
Returns nil
if no elements were removed.
Returns a new Enumerator
if no block given:
a = [:foo, 'bar', 2, :bam] a.select! # => #<Enumerator: [:foo, "bar", 2, :bam]:select!>
When invoked with a block, yield all permutations of elements of self
; returns self
. The order of permutations is indeterminate.
When a block and an in-range positive Integer
argument n
(0 < n <= self.size
) are given, calls the block with all n
-tuple permutations of self
.
Example:
a = [0, 1, 2] a.permutation(2) {|permutation| p permutation }
Output:
[0, 1] [0, 2] [1, 0] [1, 2] [2, 0] [2, 1]
Another example:
a = [0, 1, 2] a.permutation(3) {|permutation| p permutation }
Output:
[0, 1, 2] [0, 2, 1] [1, 0, 2] [1, 2, 0] [2, 0, 1] [2, 1, 0]
When n
is zero, calls the block once with a new empty Array
:
a = [0, 1, 2] a.permutation(0) {|permutation| p permutation }
Output:
[]
When n
is out of range (negative or larger than self.size
), does not call the block:
a = [0, 1, 2] a.permutation(-1) {|permutation| fail 'Cannot happen' } a.permutation(4) {|permutation| fail 'Cannot happen' }
When a block given but no argument, behaves the same as a.permutation(a.size)
:
a = [0, 1, 2] a.permutation {|permutation| p permutation }
Output:
[0, 1, 2] [0, 2, 1] [1, 0, 2] [1, 2, 0] [2, 0, 1] [2, 1, 0]
Returns a new Enumerator
if no block given:
a = [0, 1, 2] a.permutation # => #<Enumerator: [0, 1, 2]:permutation> a.permutation(2) # => #<Enumerator: [0, 1, 2]:permutation(2)>
Returns an array with both a numeric
and a int
represented as Integer
objects or Float
objects.
This is achieved by converting numeric
to an Integer
or a Float
.
A TypeError
is raised if the numeric
is not an Integer
or a Float
type.
(0x3FFFFFFFFFFFFFFF+1).coerce(42) #=> [42, 4611686018427387904]
Returns an integer that is a “floor” value for self
, as specified by the given ndigits
, which must be an integer-convertible object.
When self
is zero, returns zero (regardless of the value of ndigits
):
0.floor(2) # => 0 0.floor(-2) # => 0
When self
is non-zero and ndigits
is non-negative, returns self
:
555.floor # => 555 555.floor(50) # => 555
When self
is non-zero and ndigits
is negative, returns a value based on a computed granularity:
The granularity is 10 ** ndigits.abs
.
The returned value is the largest multiple of the granularity that is less than or equal to self
.
Examples with positive self
:
ndigits | Granularity | 1234.floor(ndigits) |
---|---|---|
-1 | 10 | 1230 |
-2 | 100 | 1200 |
-3 | 1000 | 1000 |
-4 | 10000 | 0 |
-5 | 100000 | 0 |
Examples with negative self
:
ndigits | Granularity | -1234.floor(ndigits) |
---|---|---|
-1 | 10 | -1240 |
-2 | 100 | -1300 |
-3 | 1000 | -2000 |
-4 | 10000 | -10000 |
-5 | 100000 | -100000 |
Related: Integer#ceil
.
Returns self
modulo other
as a real number.
For integer n
and real number r
, these expressions are equivalent:
n % r n-r*(n/r).floor n.divmod(r)[1]
See Numeric#divmod
.
Examples:
10 % 2 # => 0 10 % 3 # => 1 10 % 4 # => 2 10 % -2 # => 0 10 % -3 # => -2 10 % -4 # => -2 10 % 3.0 # => 1.0 10 % Rational(3, 1) # => (1/1)
Returns the remainder after dividing self
by other
.
Examples:
11.remainder(4) # => 3 11.remainder(-4) # => 3 -11.remainder(4) # => -3 -11.remainder(-4) # => -3 12.remainder(4) # => 0 12.remainder(-4) # => 0 -12.remainder(4) # => 0 -12.remainder(-4) # => 0 13.remainder(4.0) # => 1.0 13.remainder(Rational(4, 1)) # => (1/1)