Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/radix/operator.rb

Overview

Adds the b(base) method to this ruby class for quickly creating Radix instances.

Instance Method Summary collapse

Instance Method Details

#asciiObject


47
# File 'lib/radix/operator.rb', line 47

alias :ascii :b

#b(base = nil) ⇒ Radix::Integer, Radix::Float

Takes a String and makes it into a Radix::Integer or Radix::Float as given base. Float is determined by a “.” character in string instance

Parameters:

  • base (Fixnum, Array<String>) (defaults to: nil)

    The desired base.

Returns:


62
63
64
65
66
67
68
69
70
# File 'lib/radix/operator.rb', line 62

def b(base=nil)
  return ascii unless base

  if index('.')
    Radix::Float.new(self, base)
  else
    Radix::Integer.new(self, base)
  end
end