Skip to content
instance method

Integer#digits

(?::int base) -> ::Array[::Integer]
digits(base = 10) → array_of_integers

Returns an array of integers representing the base-radix digits of self; the first element of the array represents the least significant digit:

Example
12345.digits      # => [5, 4, 3, 2, 1]
12345.digits(7)   # => [4, 6, 6, 0, 5]
12345.digits(100) # => [45, 23, 1]

Raises an exception if self is negative or base is less than 2.

See also #denominator #div #coerce #divmod also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0