Class: Gondler::REPL
- Inherits:
-
Object
- Object
- Gondler::REPL
- Defined in:
- lib/gondler/repl.rb
Class Method Summary collapse
Instance Method Summary collapse
- #builtin ⇒ Object
- #builtin_commands ⇒ Object
- #execute(line) ⇒ Object
-
#initialize ⇒ REPL
constructor
A new instance of REPL.
- #run ⇒ Object
Constructor Details
#initialize ⇒ REPL
Returns a new instance of REPL.
9 10 |
# File 'lib/gondler/repl.rb', line 9 def initialize end |
Class Method Details
.run ⇒ Object
5 6 7 |
# File 'lib/gondler/repl.rb', line 5 def self.run new.run end |
Instance Method Details
#builtin ⇒ Object
28 29 30 |
# File 'lib/gondler/repl.rb', line 28 def builtin @builtin ||= builtin_commands.keys + ['help'] end |
#builtin_commands ⇒ Object
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 |
#run ⇒ Object
12 13 14 15 16 |
# File 'lib/gondler/repl.rb', line 12 def run while (buf = Readline.readline("> ", true)) execute(buf) end end |