Skip to content

Commit

Permalink
Run REPL on empty arguments to bin/keisan
Browse files Browse the repository at this point in the history
  • Loading branch information
project-eutopia committed Jan 4, 2018
1 parent 5f1b51d commit 1e96ca1
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
7 changes: 0 additions & 7 deletions bin/ikeisan

This file was deleted.

1 change: 1 addition & 0 deletions bin/keisan
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ ARGV.each do |arg|
file_name = arg
end
end

Keisan::Interpreter.new(allow_recursive: allow_recursive).run(file_name)
15 changes: 11 additions & 4 deletions lib/keisan/interpreter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,20 @@ def run_from_stdin
end

def run_from_file(file_name)
run_on_content File.open(file_name) do |file|
file.read
end
run_on_content(
File.exists?(file_name) ? File.open(file_name) do |file|
file.read
end : ""
)
end

def run_on_content(content)
calculator.evaluate(content)
content = content.strip
if content.nil? || content.empty?
Repl.new.start
else
calculator.evaluate(content)
end
end
end
end
1 change: 1 addition & 0 deletions lib/keisan/repl.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require "coderay"
require "readline"

module Keisan
Expand Down

0 comments on commit 1e96ca1

Please sign in to comment.