Class: R2do::Commands::Option

Inherits:
R2do::Command show all
Defined in:
lib/r2do/option.rb

Instance Attribute Summary

Attributes inherited from R2do::Command

#description, #extended, #short

Instance Method Summary collapse

Methods inherited from R2do::Command

#help, #to_s

Constructor Details

#initialize(short, extended, description, callback) ⇒ Option

Creates an instance of a Command

Parameters:

  • short (String)

    the short option name for this command

  • extended (String)

    the full option name for this command

  • argument (String)

    the optional argument for commands that have arguments

  • description (String)

    the command’s description

  • callback (callback)

    the callback method for this command



29
30
31
32
33
34
35
36
37
# File 'lib/r2do/option.rb', line 29

def initialize(short, extended, description, callback)
  super(short, extended, description)

  if callback.nil?
    raise ArgumentError
  end

  @callback = callback
end

Instance Method Details

#execute(args) ⇒ void

This method returns an undefined value.

Executes the callback of this command

Parameters:

  • args (Array)

    the collection of arguments



43
44
45
# File 'lib/r2do/option.rb', line 43

def execute(args)
  @callback.call(args)
end