Class: Subtle::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/subtle/cli.rb

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ CLI

Returns a new instance of CLI.



3
4
5
# File 'lib/subtle/cli.rb', line 3

def initialize(argv)
  repl # Just start the REPL for now
end

Instance Method Details

#replObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/subtle/cli.rb', line 7

def repl
  require "readline"
  prompt = "> "

  evaluator = Evaluator.new
  loop do
    line = Readline::readline(prompt)

    if line.nil? or line == "exit"
      puts if line.nil?
      puts "Bye!"
      exit 0
    end

    next if line.empty?

    Readline::HISTORY << line

    begin
      p evaluator.eval line
    rescue Exception => e
      puts e.message
      puts e.backtrace
    end
  end
end