Sha256: b237412f69124c1fd0689f86a5b63275aec151d6cf72fded04eb7ad06b4ae4d9

Contents?: true

Size: 785 Bytes

Versions: 3

Compression:

Stored size: 785 Bytes

Contents

#!/usr/bin/env ruby

require File.join(File.dirname(__FILE__), "..", "lib", "maths")

# The main script!

parser = Maths::Calculator.new


puts
puts "Welcome to maths (version #{Maths::VERSION})!"
puts "Type \"exit\" to quit."
puts

Readline.completion_proc = Proc.new do |str|
  # TODO: Get this working
end

prompt = "maths> "
while command = Readline.readline(prompt, true)
  break if /exit/i =~ command
  
  if command == "vars" || command == "variables"
    puts
    puts "Defined Variables:"
    Maths::Brain.read.each do |key, value|
      puts "#{key}: #{value}"
    end
    puts
  else
    begin
      result = parser.parse(command)

      puts "= #{Maths::Formatter.format(result)}"
      Maths::Brain.assign("$", result)
    rescue ParseError
      puts $!
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
maths-0.0.8 bin/maths
maths-0.0.7 bin/maths
maths-0.0.6 bin/maths