Class: ShellBase

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

Defined Under Namespace

Classes: Exit

Constant Summary collapse

VERSION =
"0.1.2"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeShellBase

Returns a new instance of ShellBase.



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

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name) ⇒ Object



20
21
22
# File 'lib/shell_base.rb', line 20

def method_missing(method_name)
  puts method_name.to_s + ": Command not found"
end

Class Method Details

.prompt(s) ⇒ Object



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

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

Instance Method Details

#exitObject

Raises:



15
16
17
18
# File 'lib/shell_base.rb', line 15

def exit
  puts "bye."
  raise Exit
end

#readlineObject



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/shell_base.rb', line 24

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

  begin
    send(cmd, *input)
  rescue Exit
    return false
  end
  true
end