Sha256: 08383c7fbd79f6994db75bb96d47db7249f9bb09b01c8f4247c85faa261e3983

Contents?: true

Size: 590 Bytes

Versions: 1

Compression:

Stored size: 590 Bytes

Contents

# frozen_string_literal: true

module Boxcars
  # used by Boxcars to run ruby code
  class RubyREPL
    # Execute ruby code
    # @param code [String] The code to run
    def call(code:)
      puts "RubyREPL: #{code}".colorize(:yellow)
      output = ""
      IO.popen("ruby", "r+") do |io|
        io.puts code
        io.close_write
        output = io.read
      end
      puts "Answer: #{output}".colorize(:yellow, style: :bold)
      output
    end

    # Execute ruby code
    # @param command [String] The code to run
    def run(command)
      call(code: command)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
boxcars-0.1.6 lib/boxcars/ruby_repl.rb