class Keisan::Interpreter
Attributes
calculator[R]
Public Class Methods
new(allow_recursive: false)
click to toggle source
# File lib/keisan/interpreter.rb, line 7 def initialize(allow_recursive: false) @calculator = Calculator.new(allow_recursive: allow_recursive) end
Public Instance Methods
run(file_name)
click to toggle source
# File lib/keisan/interpreter.rb, line 11 def run(file_name) if file_name.nil? run_from_stdin else run_from_file(file_name) end end
Private Instance Methods
run_from_file(file_name)
click to toggle source
# File lib/keisan/interpreter.rb, line 25 def run_from_file(file_name) run_on_content( File.exists?(file_name) ? File.open(file_name) do |file| file.read end : "" ) end
run_from_stdin()
click to toggle source
# File lib/keisan/interpreter.rb, line 21 def run_from_stdin run_on_content STDIN.tty? ? "" : STDIN.read end
run_on_content(content)
click to toggle source
# File lib/keisan/interpreter.rb, line 33 def run_on_content(content) content = content.strip if content.nil? || content.empty? Repl.new.start else calculator.evaluate(content) end end