Removes all nil
elements from self
.
Returns self
if any elements removed, otherwise nil
.
Returns true
if no element of self
meet a given criterion.
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 a block given and no argument, 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
If argument obj
is given, returns true
if obj.===
no element, false
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
Related: Enumerable#none?
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 and no argument, 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
If argument obj
is given, returns true
if obj.===
exactly one 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: Enumerable#one?
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(7).imaginary #=> 0 Complex(9, -4).imaginary #=> -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.
Returns the absolute value (magnitude) for self
; see polar coordinates:
Complex.polar(-1, 0).abs # => 1.0
If self
was created with rectangular coordinates, the returned value is computed, and may be inexact:
Complex.rectangular(1, 1).abs # => 1.4142135623730951 # The square root of 2.
Returns the argument (angle) for self
in radians; see polar coordinates:
Complex.polar(3, Math::PI/2).arg # => 1.57079632679489660
If self
was created with rectangular coordinates, the returned value is computed, and may be inexact:
Complex.polar(1, 1.0/3).arg # => 0.33333333333333326
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 array [self.abs, self.arg]
:
Complex.polar(1, 2).polar # => [1.0, 2.0]
See Polar Coordinates.
If self
was created with rectangular coordinates, the returned value is computed, and may be inexact:
Complex.rect(1, 1).polar # => [1.4142135623730951, 0.7853981633974483]
Returns the conjugate of self
, Complex.rect(self.imag, self.real)
:
Complex.rect(1, 2).conj # => (1-2i)
Returns the conjugate of self
, Complex.rect(self.imag, self.real)
:
Complex.rect(1, 2).conj # => (1-2i)
Returns true
if both self.real.finite?
and self.imag.finite?
are true, false
otherwise:
Complex(1, 1).finite? # => true Complex(Float::INFINITY, 0).finite? # => false
Related: Numeric#finite?
, Float#finite?
.
Returns 1
if either self.real.infinite?
or self.imag.infinite?
is true, nil
otherwise:
Complex(Float::INFINITY, 0).infinite? # => 1 Complex(1, 1).infinite? # => nil
Related: Numeric#infinite?
, Float#infinite?
.
Returns zero if self
is positive, Math::PI otherwise.
Returns array [self, 0]
.