Method: Commandant::Command#initialize

Defined in:
lib/commandant/command.rb

#initialize(name, description = nil, &command) ⇒ Command

Create a new command by name and add it to the commands list.

Parameters:

  • name (Symbol)

    the name of the command

  • description (String, nil) (defaults to: nil)

    the command’s description

Raises:

  • (ArgumentError)

    if a command block is not provided

  • (ArgumentError)

    if a command already exists by that name



11
12
13
14
15
16
17
18
19
20
# File 'lib/commandant/command.rb', line 11

def initialize(name, description=nil, &command)
  raise ArgumentError, "Must provide a command block" unless command
  raise ArgumentError, "Command already exists: #{name}" if COMMANDS[name]

  @name        = name
  @description = description
  @command     = command

  COMMANDS[@name] = self
end