Class: Shellissimo::Command
- Inherits:
-
Object
- Object
- Shellissimo::Command
- Defined in:
- lib/shellissimo/command.rb
Instance Attribute Summary collapse
-
#aliases ⇒ Object
readonly
Returns the value of attribute aliases.
-
#block ⇒ Object
Returns the value of attribute block.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#param_definitions ⇒ Object
readonly
Returns the value of attribute param_definitions.
Instance Method Summary collapse
- #call(*args) ⇒ Object (also: #[])
-
#initialize(name, description = "", aliases = [], param_definitions = [], &block) ⇒ Command
constructor
A new instance of Command.
- #prepend_params(params) ⇒ Object
- #to_proc ⇒ Object
Constructor Details
#initialize(name, description = "", aliases = [], param_definitions = [], &block) ⇒ Command
Returns a new instance of Command.
8 9 10 11 12 |
# File 'lib/shellissimo/command.rb', line 8 def initialize(name, description = "", aliases = [], param_definitions = [], &block) @name, @description = CommandName.new(name, aliases), String(description) @param_definitions = Array(param_definitions) self.block = block end |
Instance Attribute Details
#aliases ⇒ Object (readonly)
Returns the value of attribute aliases.
6 7 8 |
# File 'lib/shellissimo/command.rb', line 6 def aliases @aliases end |
#block ⇒ Object
Returns the value of attribute block.
6 7 8 |
# File 'lib/shellissimo/command.rb', line 6 def block @block end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
6 7 8 |
# File 'lib/shellissimo/command.rb', line 6 def description @description end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/shellissimo/command.rb', line 6 def name @name end |
#param_definitions ⇒ Object (readonly)
Returns the value of attribute param_definitions.
6 7 8 |
# File 'lib/shellissimo/command.rb', line 6 def param_definitions @param_definitions end |
Instance Method Details
#call(*args) ⇒ Object Also known as: []
24 25 26 |
# File 'lib/shellissimo/command.rb', line 24 def call(*args) block.call(*args) end |
#prepend_params(params) ⇒ Object
18 19 20 21 22 |
# File 'lib/shellissimo/command.rb', line 18 def prepend_params(params) params = filter_params(params) old_block = block # let's fool ruby dup.tap { |c| c.block = proc { instance_exec(params, &old_block) } } end |
#to_proc ⇒ Object
29 30 31 |
# File 'lib/shellissimo/command.rb', line 29 def to_proc block end |