FANDOM


Numeric is the base class for numeric types, including the built-in classes Integer and Float.

Inherits: Object.

Mixins: Comparable.

MethodsEdit

MethodParametersDescription
==1Returns true if self is equal to the parameter, based on the <=> operator.
>1Returns true if self is greater than the parameter, based on the <=> operator.
>=1Returns true if self is greater than or equal to the parameter, based on the <=> operator.
<1Returns true if self is less than the parameter, based on the <=> operator.
<=1Returns true if self is less than or equal to the parameter, based on the <=> operator.
<=>1"Spaceship" operator. Returns -1 if self is less than the parameter, 0 if equal, +1 if greater.
-@0Unary minus. Returns the negation of self.
+@0Unary plus. Returns self unchanged.
abs0Returns the absolute value of self.
between?2self.between(min, max) returns true if self is not less than min and not greater than max. The limits are part of the range, so 2.between?(2, 6) returns true.
ceil0Returns the least integer that is not less than self.
coerce1self.coerce(other) returns an Array representing other and self in that order. If self and other have the same type, they are returned unchanged; otherwise, both are converted to Float.
divmod1self.divmod(other) returns an Array containing the integer quotient and the remainder, in that order, resulting from dividing self by other. The quotient is an Integer and is rounded downward; the remainder is either an Integer or a Float and satisfies (quo*other+rem) == self. This is equivalent to [self.div(other), self.modulo(other)], except that self and other are evaluated only once.
div1self.div(other) returns the integer quotient that results from dividing self by other. The quotient is an Integer and is rounded down. Equivalent to self.quo(other).floor and to self.divmod(other)[0].
eql?1self.eql?(other) returns true if self and other have the same type and equal values.
floor0Returns the greatest integer that is not greater than self.
integer?0Returns false. Integers will override this.
modulo1self.modulo(other) returns the remainder that results from dividing self by other. The remainder has the same sign as other.
nonzero?0Returns true if self is not equal to zero.
quo1self.quo(other) returns the result of self divided by other as a Float.
remainder1self.remainder(other) returns the remainder that results from dividing self by other. Different from modulo in that the remainder is derived by rounding the quotient toward zero rather than downward and has the same sign as self; the sign of other is ignored.
round0Rounds self to the nearest integer, with ties rounding away from zero.
step1 or 2self.step(limit, stride) calls a passed block, passing it self the first time, and then self+stride, self+2*stride, and so on until the limit is exceeded. A step value that is equal to the limit will call the block one last time. If stride is not present, it is taken to be 1.
to_int0Converts self to an Integer. Not usefully defined by Numeric, but common to all derived classes.
truncate0Rounds toward zero; that is, returns the Integer with greatest absolute value that has the same sign as self and absolute value not greater than that of self.
zero?0Returns true if self is equal to zero.

New in Ruby 1.9Edit

MethodParametersDescription
fdiv1A synonym for quo.
round0 or 1With no parameter, round behaves as in Ruby 1.8. An optional numeric parameter gives the number of digits to the right of the decimal point to which self is to be rounded. This number may be negative, in which case self will be rounded to a power of ten equal to the negation of the digit count. If the number of digits is positive, the return value is a Float; otherwise it is an Integer.
scalar?0Returns true.

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.