lib/boxcars/ruby_repl.rb in boxcars-0.2.0 vs lib/boxcars/ruby_repl.rb in boxcars-0.2.1
- old
+ new
@@ -7,22 +7,23 @@
# @param code [String] The code to run
def call(code:)
Boxcars.debug "RubyREPL: #{code}", :yellow
# wrap the code in an excption block so we can catch errors
- code = "begin\n#{code}\nrescue Exception => e\n puts 'Error: ' + e.message\nend"
+ wrapped = "begin\n#{code}\nrescue Exception => e\n puts 'Error: ' + e.message\nend"
output = ""
IO.popen("ruby", "r+") do |io|
- io.puts code
+ io.puts wrapped
io.close_write
output = io.read
end
if output =~ /^Error: /
- Boxcars.error output
- output
+ Boxcars.debug output, :red
+ Result.from_error(output, code: code)
+ else
+ Boxcars.debug "Answer: #{output}", :yellow, style: :bold
+ Result.from_text(output, code: code)
end
- Boxcars.debug "Answer: #{output}", :yellow, style: :bold
- output
end
# Execute ruby code
# @param command [String] The code to run
def run(command)