Module: Cmd::ClassMethods

### Home Classes Methods

### In Files

- lib/cmd.rb

### Methods

- ::custom_exception_handlers
- ::docs
- ::handle
- ::prompt
- ::shortcut_table
- ::shortcuts
- #define_collect_method
- #doc
- #prompt_with
- #shortcut

### Files

- AUTHORS
- CHANGELOG
- INSTALL
- README
- THANKS
- TODO

### Class/Module Index

Quicksearch

- Cmd
- Cmd::ClassMethods
- Object

No matching classes.

# Cmd::ClassMethods

### Public Class Methods

custom_exception_handlers() click to toggle source

    # File lib/cmd.rb, line 99
    def custom_exception_handlers
      @@handlers
    end

docs() click to toggle source

    # File lib/cmd.rb, line 34
    def docs
      @@docs
    end

handle(exception, handler) click to toggle source

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

prompt() click to toggle source

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

shortcut_table() click to toggle source

    # File lib/cmd.rb, line 89
    def shortcut_table
      @@shortcut_table
    end

shortcuts() click to toggle source

    # File lib/cmd.rb, line 94
    def shortcuts
      @@shortcuts
    end

### Public Instance Methods

define_collect_method(prefix) click to toggle source

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

doc(command, docstring = nil) click to toggle source

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

prompt_with(*p, &block) click to toggle source

Sets what the prompt is. Accepts a String, a block or a Symbol.

## Block

    prompt_with { Time.now }

## Symbol

    prompt_with :set_prompt

## String

    prompt_with "#{self.class.name}> "

    # File lib/cmd.rb, line 62
    def prompt_with(*p, &block)
      @@prompt = block_given? ? block : p.first
    end

shortcut(short, command) click to toggle source

Create a command short cut

    shortcut '?', 'help'
    def do_help
      # etc
    end

    # File lib/cmd.rb, line 84
    def shortcut(short, command)
      (@@shortcuts[command.to_s] ||= []).push short
      @@shortcut_table[short] = command.to_s
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.