Name
Numeric — Superclass of all concrete numbers
Synopsis
Numeric
provides common behavior of numbers. Numeric is an
abstract class, so you should not instantiate this class.
Included Module
Comparable
Instance Methods
+nReturns
n.-nReturns
nnegated.n+ numn- numn* numn/ numPerforms arithmetic operations: addition, subtraction, multiplication, and division.
n% numReturns the modulus of
n.n** numExponentiation.
n.absReturns the absolute value of
n.n.ceilReturns the smallest integer greater than or equal to
n.n.coerce(num)Returns an array containing
numandnboth possibly converted to a type that allows them to be operated on mutually. Used in automatic type conversion in numeric operators.n.divmod(num)Returns an array containing the quotient and modulus from dividing
nbynum.n.floorReturns the largest integer less than or equal to
n.1.2.floor #=> 1 2.1.floor #=> 2 (-1.2).floor #=> -2 (-2.1).floor #=> -3
n.integer?Returns
trueifnis an integer.n.modulo(num)Returns the modulus obtained by dividing
nbynumand rounding the quotient withfloor. Equivalent ton.divmod(num)[1].n.nonzero?Returns
nif it isn’t zero, otherwisenil.n.remainder(num)Returns the remainder obtained by dividing
nbynumand removing decimals from the quotient. The result and n always have same sign.(13.modulo(4)) #=> 1 (13.modulo(-4)) #=> -3 ((-13).modulo(4)) #=> 3 ((-13).modulo(-4)) #=> -1 (13.remainder(4)) #=> 1 (13.remainder(-4)) #=> 1 ((-13).remainder(4)) #=> -1 (-13).remainder(-4)) #=> -1
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access