Sha256: 1598cfe8f1a2903b91e040fa640fc67b74913b55ea3c1ebc6e9fd7d947c79b8b

Contents?: true

Size: 749 Bytes

Versions: 1

Compression:

Stored size: 749 Bytes

Contents

module Polyfill
  module V2_4
    module Integer
      module Digits
        module Method
          def digits(base = 10)
            base = base.to_int
            raise Math::DomainError, 'out of domain' if self < 0
            raise ArgumentError, 'negative radix' if base < 0
            raise ArgumentError, "invalid radix #{base}" if base < 2

            acc = []
            remainder = self
            while remainder > 0
              remainder, value = remainder.divmod(base)
              acc.push(value)
            end
            acc
          end if RUBY_VERSION < '2.4.0'
        end

        if RUBY_VERSION < '2.4.0'
          refine ::Integer do
            include Method
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
polyfill-0.2.0 lib/polyfill/v2_4/integer/digits.rb