class Fixnum

Public Instance Methods

_rdoba_to_s(base = 10, *opts)
Alias for: to_s
to_s(base = 10, *opts) click to toggle source
# File lib/rdoba/numeric.rb, line 27
def to_s(base = 10, *opts)
  v = parse_opts(opts)

  return _rdoba_to_s(base) unless v[:padding] or v[:style_formatting]

  raise "Base of number can't be equal or less then zero" if base <= 0
  raise "Padding count numberr can't be equal or less then zero" if v[:padding] <= 0
  value = self
  minus = if value < 0
      value = -value
      true
    end
  res = ''
  while value != 0
    value, rem = value.divmod(base)
    rem += 0x40 - 0x39 if rem >= 10
    res += (0x30 + rem).chr
  end
  res += "0" * (v[:padding].to_i - res.size) if res.size < v[:padding].to_i
  res += 'x0' if v[:style_formatting] and base == 16
  res += '-' if minus
  res.reverse
end
Also aliased as: _rdoba_to_s