bin/flea in flea-0.1.0 vs bin/flea in flea-0.1.1
- old
+ new
@@ -1,39 +1,41 @@
#!/usr/bin/env ruby
+# frozen_string_literal: true
-require 'stringio'
-require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'flea.rb'))
+require 'bundler/setup'
+require 'flea'
interpreter = Flea::Interpreter.new
-if ARGV.length > 0
+if ARGV.length.positive?
interpreter.run(ARGF.read)
exit
end
loop do
program = []
indent = 0
loop do
- print "> " + (" " * indent)
+ print "> #{' ' * indent}"
program << gets
-
- tmp_program = program.join(" ")
- open_p_count = tmp_program.count("(")
- close_p_count = tmp_program.count(")")
-
+
+ tmp_program = program.join(' ')
+ open_p_count = tmp_program.count('(')
+ close_p_count = tmp_program.count(')')
+
break if open_p_count == close_p_count
- indent += 1 if program.last.count("(") > program.last.count(")")
- indent -= 1 if program.last.count("(") < program.last.count(")")
+
+ indent += 1 if program.last.count('(') > program.last.count(')')
+ indent -= 1 if program.last.count('(') < program.last.count(')')
end
- program = program.join(" ")
- exit if program.strip == "quit"
-
+ program = program.join(' ')
+ exit if program.strip == 'quit'
+
old_stdout = $stdout
buffer = StringIO.new
$stdout = buffer
result = interpreter.run program
$stdout = old_stdout
print buffer.string
print "\n" unless buffer.string.empty?
puts " => #{result.inspect}"
-end
\ No newline at end of file
+end