Integer

The abstract class for integers. Its subclasses are Fixnum and Bignum. These two types of integers are automatically converted into one another according to their values. Integers can be treated as infinite bit strings for bit operations.

Superclass

Methods

self[nth]

Returns 1 if the nth bit of the integer is set (with the LSB, or least significant bit, at position 0), otherwise returns 0.

self[nth]=bit is not an Integer method because the associated Numeric class is immutable.

self + other
self - other
self * other
self / other
self % other
self ** other

Arithmetic operators. Compute the sum, difference, product, quotient, remainder, and exponent respectively.

self <=> other

Compares self with other; returns a positive integer if self is larger, 0 if the two are equal, and a negative integer if self is smaller.

self == other
self < other
self <= other
self > other
self >= other

Relational operators.

~ self
self | other
self & other
self ^ other

Bit operators. Compute bitwise negation, logical OR, logical AND, and logical XOR respectively.

self << bits
self >> bits

Shift operators. Shift only bits to the right or left.

The signed bit (MSB or most significant bit) is retained in a right shift.

chr

Returns a 1-byte string corresponding to the numeric position in the character set. For example, 65.chr returns "A".

The integer must be within the range of 0 to 255. Calling this method with an out-of-range integer will throw a RangeError exception.

downto(min) {|n| ... }

Iterates from self to min, decrementing by 1. If self < min, does nothing.

See also upto, step, and times.

next
succ

Returns the "next" value of an integer.

step(limit, step) {|n| ... }

Iteratively evaluates a block from self, incrementing by step, until limit is about to be surpassed. step can also be a negative number.

When step is set to 0, throws an ArgumentError exception.

Returns self.

See also upto, downto, and times.

times {|n| ... }

Iterates self number of times, from 0 to self-1. If self is negative, does nothing.

Returns self.

See also upto, downto, and step.

to_f

Converts a value to a floating point integer (Float).

to_s([base])

Converts an integer to a base-10 string expression.

If an argument is specified, it will be used as the base number for conversion. If a base outside the range of 2-36 is specified, an ArgumentError exception will be thrown.

p 10.to_s(2)    # => "1010"
p 10.to_s(8)    # => "12"
p 10.to_s(16)   # => "a"
p 35.to_s(36)   # => "z"
upto(max) {|n| ... }

Iterates from self to max, incrementing by 1. If self > max, does nothing.

Returns self.

See also downto, step, and times.

Converted from CHM to HTML with chm2web Pro 2.85 (unicode)