Class: Gondler::REPL

Inherits:
Object
  • Object
show all
Defined in:
lib/gondler/repl.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeREPL

Returns a new instance of REPL.



9
10
# File 'lib/gondler/repl.rb', line 9

def initialize
end

Class Method Details

.runObject



5
6
7
# File 'lib/gondler/repl.rb', line 5

def self.run
  new.run
end

Instance Method Details

#builtinObject



28
29
30
# File 'lib/gondler/repl.rb', line 28

def builtin
  @builtin ||= builtin_commands.keys + ['help']
end

#builtin_commandsObject



32
33
34
# File 'lib/gondler/repl.rb', line 32

def builtin_commands
  @builtin_commands ||= Gondler::CLI.commands
end

#execute(line) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/gondler/repl.rb', line 18

def execute(line)
  cmd = line.match(/\A\w+/).to_s

  if builtin.include?(cmd)
    Gondler::CLI.start(line.split(/\s+/))
  else
    system(line)
  end
end

#runObject



12
13
14
15
16
# File 'lib/gondler/repl.rb', line 12

def run
  while (buf = Readline.readline("> ", true))
    execute(buf)
  end
end