# File lib/cmd.rb, line 99 def custom_exception_handlers @@handlers end
Set what to do in the event that the given exception is raised.
handle StackOverflowError, :handle_stack_overflow
# File lib/cmd.rb, line 43 def handle(exception, handler) @@handlers[exception.to_s] = handler end
Returns the evaluation of expression passed to prompt_with. Result has to_s called on it as Readline expects a String for its prompt. XXX This could probably be more robust
# File lib/cmd.rb, line 69 def prompt case @@prompt when Symbol: self.send @@prompt when Proc: @@prompt.call else @@prompt end.to_s end
Defines a method which returns all defined methods which start with the passed in prefix followed by an underscore. Used to define methods to collect things such as all defined 'complete' and 'do' methods.
# File lib/cmd.rb, line 107 def define_collect_method(prefix) method = 'collect_' + prefix unless self.respond_to?(method) define_method(method) do self.methods.grep(/^#{prefix}_/).map {|meth| meth[prefix.size + 1..-1]} end end end
Set documentation for a command
doc :help, 'Display this help.' def do_help # etc end
# File lib/cmd.rb, line 29 def doc(command, docstring = nil) docstring = docstring ? docstring : yield @@docs[command.to_s] = docstring end
Sets what the prompt is. Accepts a String, a block or a Symbol.
prompt_with { Time.now }
prompt_with :set_prompt
prompt_with "#{self.class.name}> "
# File lib/cmd.rb, line 62 def prompt_with(*p, &block) @@prompt = block_given? ? block : p.first end
Generated with the Darkfish Rdoc Generator 2.