A simple, though not very effective or safe way to do this for arbitrary databases:
class Fixnum
def as_base(b)
to_s.to_i(b)
end
end
101010.as_base(2)
42
(And you will need to do the same class Bignumfor working with arbitrarily large integer literals ...)
source
share