Module: Radix
- Defined in:
- lib/radix.rb,
lib/radix/base.rb,
lib/radix/float.rb,
lib/radix/integer.rb,
lib/radix/numeric.rb,
lib/radix/rational.rb
Defined Under Namespace
Modules: BASE Classes: Base, Float, Integer, Numeric, Rational
Constant Summary collapse
- VERSION =
TODO: Here only for buggy RUby 1.8.x.
['version']
- DOT =
Redix separator used in string and array representations.
'.'
- DIV =
'/'
- DIVIDER =
" "
Class Method Summary collapse
- .const_missing(name) ⇒ Object
-
.convert(number, from_base, to_base) ⇒ Object
Convert number from it’s given base to antoher base.
-
.convert_base(digits, from_base, to_base) ⇒ Object
Convert any base to any other base, using array of
digits
. - .metadata ⇒ Object
Class Method Details
.const_missing(name) ⇒ Object
15 16 17 18 |
# File 'lib/radix.rb', line 15 def self.const_missing(name) key = name.to_s.downcase [key] || super(name) end |
.convert(number, from_base, to_base) ⇒ Object
Convert number from it’s given base to antoher base. Do a standard conversion upto base 62.
107 108 109 110 111 |
# File 'lib/radix/base.rb', line 107 def self.convert(number, from_base, to_base) from_base = Radix::Base.new(from_base) unless Radix::Base === from_base to_base = Radix::Base.new(to_base) unless Radix::Base === to_base to_base.convert(number, from_base) end |
.convert_base(digits, from_base, to_base) ⇒ Object
Convert any base to any other base, using array of digits
.
114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/radix/base.rb', line 114 def self.convert_base(digits, from_base, to_base) bignum = 0 digits.each { |digit| bignum = bignum * from_base + digit } converted = [] until bignum.zero? bignum, digit = bignum.divmod(to_base) converted.push(digit) end converted << 0 if converted.empty? # THINK: correct? converted.reverse end |
.metadata ⇒ Object
8 9 10 11 12 13 |
# File 'lib/radix.rb', line 8 def self. @metadata ||= ( require 'yaml' YAML.load(File.new(File.dirname(__FILE__) + '/radix.yml')) ) end |