Class: ShellBase

Inherits:
Object
  • Object
show all
Defined in:
lib/shell_base.rb,
lib/shell_base/version.rb

Constant Summary collapse

VERSION =
"0.1.1"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeShellBase

Returns a new instance of ShellBase.



9
10
11
12
# File 'lib/shell_base.rb', line 9

def initialize
  @prompt = @@default_prompt
  while readline; end
end

Class Method Details

.prompt(s) ⇒ Object



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

def self.prompt(s)
  @@default_prompt = s
end

Instance Method Details

#readlineObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/shell_base.rb', line 14

def readline
  input = Readline.readline(@prompt, true).split(" ")
  cmd = input.shift

  return if cmd == 'exit'
  if respond_to? cmd
    send(cmd, *input)
  else
    puts cmd + ": Command not found"
  end
  true
end