Results for: "minmax"

No documentation available
No documentation available
No documentation available

Returns the new String formed by calling method #inspect on each array element:

a = [:foo, 'bar', 2]
a.inspect # => "[:foo, \"bar\", 2]"

Array#to_s is an alias for Array#inspect.

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?:

[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

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 the index of a specified element.

When argument object is given but no block, returns the index of the first element element for which object == element:

a = [:foo, 'bar', 2, 'bar']
a.index('bar') # => 1

Returns nil if no such element found.

When both argument object and a block are given, calls the block with each successive element; returns the index of the first element for which the block returns a truthy value:

a = [:foo, 'bar', 2, 'bar']
a.index {|element| element == 'bar' } # => 1

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]
e = a.index
e # => #<Enumerator: [:foo, "bar", 2]:index>
e.each {|element| element == 'bar' } # => 1

Array#find_index is an alias for Array#index.

Related: rindex.

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.

Returns the new String formed by joining the array elements after conversion. For each element element:

With no argument, joins using the output field separator, $,:

a = [:foo, 'bar', 2]
$, # => nil
a.join # => "foobar2"

With string argument separator, joins using that separator:

a = [:foo, 'bar', 2]
a.join("\n") # => "foo\nbar\n2"

Joins recursively for nested Arrays:

a = [:foo, [:bar, [:baz, :bat]]]
a.join # => "foobarbazbat"

Calls the block, if given, 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]

Returns a new Enumerator if no block given:

a = [:foo, 'bar', 2]
a1 = a.map
a1 # => #<Enumerator: [:foo, "bar", 2]:map>

Array#collect is an alias for Array#map.

Calls the block, if given, with each element; replaces the element with the block’s return value:

a = [:foo, 'bar', 2]
a.map! { |element| element.class } # => [Symbol, String, Integer]

Returns a new Enumerator if no block given:

a = [:foo, 'bar', 2]
a1 = a.map!
a1 # => #<Enumerator: [:foo, "bar", 2]:map!>

Array#collect! is an alias for Array#map!.

Returns true if for some index i in self, obj == self[i]; otherwise false:

[0, 1, 2].include?(2) # => true
[0, 1, 2].include?(3) # => false

Calls the block, if given, with combinations of elements of self; returns self. The order of combinations 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 combinations of self.

Example:

a = [0, 1, 2]
a.combination(2) {|combination| p combination }

Output:

[0, 1]
[0, 2]
[1, 2]

Another example:

a = [0, 1, 2]
a.combination(3) {|combination| p combination }

Output:

[0, 1, 2]

When n is zero, calls the block once with a new empty Array:

a = [0, 1, 2]
a1 = a.combination(0) {|combination| p combination }

Output:

[]

When n is out of range (negative or larger than self.size), does not call the block:

a = [0, 1, 2]
a.combination(-1) {|combination| fail 'Cannot happen' }
a.combination(4) {|combination| fail 'Cannot happen' }

Returns a new Enumerator if no block given:

a = [0, 1, 2]
a.combination(2) # => #<Enumerator: [0, 1, 2]:combination(2)>

Builds a command line string from an argument list array joining all elements escaped for the Bourne shell and separated by a space.

See Shellwords.shelljoin for details.

Returns a string containing the place-value representation of self in radix base (in 2..36).

12345.to_s               # => "12345"
12345.to_s(2)            # => "11000000111001"
12345.to_s(8)            # => "30071"
12345.to_s(10)           # => "12345"
12345.to_s(16)           # => "3039"
12345.to_s(36)           # => "9ix"
78546939656932.to_s(36)  # => "rubyrules"

Raises an exception if base is out of range.

Integer#inspect is an alias for Integer#to_s.

Since int is already an Integer, this always returns true.

No documentation available

Returns the imaginary part.

Complex(7).imaginary      #=> 0
Complex(9, -4).imaginary  #=> -4

Returns the absolute part of its polar form.

Complex(-1).abs         #=> 1
Complex(3.0, -4.0).abs  #=> 5.0

Returns the value as a string for inspection.

Complex(2).inspect                       #=> "(2+0i)"
Complex('-8/6').inspect                  #=> "((-4/3)+0i)"
Complex('1/2i').inspect                  #=> "(0+(1/2)*i)"
Complex(0, Float::INFINITY).inspect      #=> "(0+Infinity*i)"
Complex(Float::NAN, Float::NAN).inspect  #=> "(NaN+NaN*i)"

Returns true if cmp‘s real and imaginary parts are both finite numbers, otherwise returns false.

Always returns the string “nil”.

Returns the absolute value of self.

12.abs        #=> 12
(-34.56).abs  #=> 34.56
-34.56.abs    #=> 34.56

Numeric#magnitude is an alias for Numeric#abs.

Returns true if num is an Integer.

1.0.integer?   #=> false
1.integer?     #=> true
Search took: 5ms  ·  Total Results: 1816