Class: Lox::Runner
- Inherits:
-
Object
- Object
- Lox::Runner
- Defined in:
- lib/loxby/runner.rb
Overview
‘Lox::Runner` is the interactive runner which kickstarts the interpreter. An instance is created when loxby is initialized from the command line, though it can be instantiated from code as well.
Instance Method Summary collapse
-
#initialize(out = $stdout, err = $stderr) ⇒ Runner
constructor
A new instance of Runner.
- #run(args) ⇒ Object
Constructor Details
#initialize(out = $stdout, err = $stderr) ⇒ Runner
Returns a new instance of Runner.
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/loxby/runner.rb', line 14 def initialize(out = $stdout, err = $stderr) # Exit cleanly. 130 is for interrupted scripts trap('INT') do puts exit Lox.config.exit_code.interrupt end @interpreter = Lox.new @out = out @err = err end |
Instance Method Details
#run(args) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/loxby/runner.rb', line 26 def run(args) if args.size > 1 @out.puts 'Usage: loxby [script]' exit Lox.config.exit_code.usage elsif args.size == 1 @interpreter.run_file args[0] else @interpreter.run_prompt # Run interactively end end |