Class: Commandant::Command
- Inherits:
-
Object
- Object
- Commandant::Command
- Defined in:
- lib/commandant/command.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
Instance Method Summary collapse
-
#call(args = nil) ⇒ Object
Execute the command.
-
#initialize(name, description = nil, &command) ⇒ Command
constructor
Create a new command by name and add it to the commands list.
Constructor Details
#initialize(name, description = nil, &command) ⇒ Command
Create a new command by name and add it to the commands list.
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 |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
3 4 5 |
# File 'lib/commandant/command.rb', line 3 def description @description end |
Instance Method Details
#call(args = nil) ⇒ Object
Execute the command
25 26 27 |
# File 'lib/commandant/command.rb', line 25 def call(args=nil) @command.call(args) end |