The top-level number type.
Creates an Array of self with the given values, which will be casted to this type with the cast method (defined in each Number type).
Returns self.
Implements the comparison operator.
Returns the absolute value of this number.
Returns the square of self (self * self).
Return a tuple of two elements containing the quotient and modulus obtained by dividing self by number.
Rounds this number to a given precision in decimal digits.
Returns the sign of this number as an Int32.
Keeps digits significants digits of this number in the given base.
Invokes the given block with the sequence of numbers starting at self, incremented by by on each call, and with an optional limit.
Creates an Array of self with the given values, which will be casted
to this type with the cast method (defined in each Number type).
floats = Float64[1, 2, 3, 4]
floats.class #=> Array(Float64)
ints = Int64[1, 2, 3]
ints.class #=> Array(Int64)Returns self.
Implements the comparison operator.
See Object#<=>
Returns the absolute value of this number.
123.abs #=> 123
-123.abs #=> 123Returns the square of self (self * self).
4.abs2 #=> 16
1.5.abs2 #=> 2.25Return a tuple of two elements containing the quotient
and modulus obtained by dividing self by number.
11.divmod(3) #=> {3, 2}
11.divmod(-3) #=> {-3, 2}Rounds this number to a given precision in decimal digits.
-1763.116.round(2) #=> -1763.12Returns the sign of this number as an Int32.
123.sign #=> 1
0.sign #=> 0
-42.sign #=> -1Keeps digits significants digits of this number in the given base.
1234.567.significant(1) #=> 1000
1234.567.significant(2) #=> 1200
1234.567.significant(3) #=> 1230
1234.567.significant(4) #=> 1235
1234.567.significant(5) #=> 1234.6
1234.567.significant(6) #=> 1234.57
1234.567.significant(7) #=> 1234.567
1234.567.significant(8) #=> 1234.567
15.159.significant(1, base = 2) #=> 16Invokes the given block with the sequence of numbers starting at self,
incremented by by on each call, and with an optional limit.
3.step(by: 2, limit: 10) do |n|
puts n
end
Output:
3
5
7
9