Class: ShellBase
- Inherits:
-
Object
show all
- Defined in:
- lib/shell_base.rb,
lib/shell_base/version.rb
Defined Under Namespace
Classes: Exit
Constant Summary
collapse
- VERSION =
"0.2.1"
Instance Method Summary
collapse
Constructor Details
7
8
9
|
# File 'lib/shell_base.rb', line 7
def initialize
while readline; end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name) ⇒ Object
19
20
21
|
# File 'lib/shell_base.rb', line 19
def method_missing(method_name)
puts method_name.to_s + ": Command not found"
end
|
Instance Method Details
#exit ⇒ Object
15
16
17
|
# File 'lib/shell_base.rb', line 15
def exit
puts "bye."; raise Exit
end
|
#prompt ⇒ Object
11
12
13
|
# File 'lib/shell_base.rb', line 11
def prompt
"$ "
end
|
#readline ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/shell_base.rb', line 23
def readline
input = Readline.readline(prompt, true).split(" ")
cmd = input.shift
if cmd
begin
send(cmd, *input)
rescue Exit
return false
end
end
true
end
|