Uninstalls gem spec
Prepends objects to the front of self
, moving other elements upwards. See also Array#shift
for the opposite effect.
a = [ "b", "c", "d" ] a.unshift("a") #=> ["a", "b", "c", "d"] a.unshift(1, 2) #=> [ 1, 2, "a", "b", "c", "d"]
Returns the number of elements.
If an argument is given, counts the number of elements which equal obj
using ==
.
If a block is given, counts the number of elements for which the block returns a true value.
ary = [1, 2, 4, 2] ary.count #=> 4 ary.count(2) #=> 2 ary.count {|x| x%2 == 0} #=> 3
Returns object. This method is deprecated and will be removed in Ruby 3.2.
Returns object. This method is deprecated and will be removed in Ruby 3.2.
Returns false. This method is deprecated and will be removed in Ruby 3.2.
Returns int
truncated (toward zero) to a precision of ndigits
decimal digits (default: 0).
When the precision is negative, the returned value is an integer with at least ndigits.abs
trailing zeros.
Returns self
when ndigits
is zero or positive.
1.truncate #=> 1 1.truncate(2) #=> 1 18.truncate(-1) #=> 10 (-18).truncate(-1) #=> -10
Returns int
rounded to the nearest value with a precision of ndigits
decimal digits (default: 0).
When the precision is negative, the returned value is an integer with at least ndigits.abs
trailing zeros.
Returns self
when ndigits
is zero or positive.
1.round #=> 1 1.round(2) #=> 1 15.round(-1) #=> 20 (-15).round(-1) #=> -20
The optional half
keyword argument is available similar to Float#round
.
25.round(-1, half: :up) #=> 30 25.round(-1, half: :down) #=> 20 25.round(-1, half: :even) #=> 20 35.round(-1, half: :up) #=> 40 35.round(-1, half: :down) #=> 30 35.round(-1, half: :even) #=> 40 (-25).round(-1, half: :up) #=> -30 (-25).round(-1, half: :down) #=> -20 (-25).round(-1, half: :even) #=> -20
Returns the absolute value of int
.
(-12345).abs #=> 12345 -12345.abs #=> 12345 12345.abs #=> 12345
Integer#magnitude
is an alias for Integer#abs
.
Returns the absolute part of its polar form.
Complex(-1).abs #=> 1 Complex(3.0, -4.0).abs #=> 5.0
Returns true
if cmp
‘s real and imaginary parts are both finite numbers, otherwise returns false
.
Returns 1
if cmp
‘s real or imaginary part is an infinite number, otherwise returns nil
.
For example: (1+1i).infinite? #=> nil (Float::INFINITY + 1i).infinite? #=> 1
Only the object nil responds true
to nil?
.
Returns the absolute value of num
.
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 a finite number, otherwise returns false
.
Returns nil
, -1, or 1 depending on whether the value is finite, -Infinity
, or +Infinity
.
Returns num
rounded to the nearest value with a precision of ndigits
decimal digits (default: 0).
Numeric
implements this by converting its value to a Float
and invoking Float#round
.