Class: Eco::CLI::Scripting::Argument
- Defined in:
- lib/eco/cli/scripting/argument.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Class Method Summary collapse
Instance Method Summary collapse
- #args_slice(*args) ⇒ Object
-
#initialize(key, with_param: false) ⇒ Argument
constructor
A new instance of Argument.
- #with_param! ⇒ Object
- #with_param? ⇒ Boolean
Constructor Details
#initialize(key, with_param: false) ⇒ Argument
Returns a new instance of Argument.
13 14 15 16 |
# File 'lib/eco/cli/scripting/argument.rb', line 13 def initialize(key, with_param: false) @key = key @with_param = !!with_param end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
5 6 7 |
# File 'lib/eco/cli/scripting/argument.rb', line 5 def key @key end |
Class Method Details
.is_modifier?(value) ⇒ Boolean
8 9 10 |
# File 'lib/eco/cli/scripting/argument.rb', line 8 def is_modifier?(value) value&.start_with?("-") end |
Instance Method Details
#args_slice(*args) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/eco/cli/scripting/argument.rb', line 18 def args_slice(*args) #pp "known arg '#{key}' => included? #{args.include?(key)}" return args unless args.include?(key) i = args.index(key) j = with_param?? i+1 : i args - args.slice(i..j) end |
#with_param! ⇒ Object
27 28 29 |
# File 'lib/eco/cli/scripting/argument.rb', line 27 def with_param! @with_param = true end |
#with_param? ⇒ Boolean
31 32 33 |
# File 'lib/eco/cli/scripting/argument.rb', line 31 def with_param? @with_param end |