Module: Nuggets::Argv::OptionMixin
- Defined in:
- lib/nuggets/argv/option_mixin.rb
Instance Method Summary collapse
-
#option(*args, &block) ⇒ Object
call-seq: ARGV.option(short[, long]) -> aString ARGV.option(short[, long]) { |value| … } -> anObject.
-
#option!(*args, &block) ⇒ Object
call-seq: ARGV.option!(short[, long]) -> aString ARGV.option!(short[, long]) { |value| … } -> anObject.
-
#switch(*args) ⇒ Object
call-seq: ARGV.switch(short[, long]) -> true | false.
-
#switch!(*args) ⇒ Object
call-seq: ARGV.switch!(short[, long]) -> true | false.
Instance Method Details
#option(*args, &block) ⇒ Object
call-seq:
ARGV.option(short[, long]) -> aString
ARGV.option(short[, long]) { |value| ... } -> anObject
Returns the value associated with the option short (or long) if present in ARGV. Yields that value to the block if given and returns its result.
45 46 47 |
# File 'lib/nuggets/argv/option_mixin.rb', line 45 def option(*args, &block) __opt(block, *args) { |index| at(index + 1) } end |
#option!(*args, &block) ⇒ Object
call-seq:
ARGV.option!(short[, long]) -> aString
ARGV.option!(short[, long]) { |value| ... } -> anObject
Returns the value associated with the option short (or long) if present in ARGV and removes both from ARGV. Yields that value to the block if given and returns its result.
65 66 67 |
# File 'lib/nuggets/argv/option_mixin.rb', line 65 def option!(*args, &block) __opt(block, *args) { |index| delete_at(index); delete_at(index) } end |
#switch(*args) ⇒ Object
call-seq:
ARGV.switch(short[, long]) -> true | false
Whether ARGV includes the switch short (or long).
35 36 37 |
# File 'lib/nuggets/argv/option_mixin.rb', line 35 def switch(*args) !!(__key(*args) { |key| include?(key) }) end |
#switch!(*args) ⇒ Object
call-seq:
ARGV.switch!(short[, long]) -> true | false
Whether ARGV includes the switch short (or long). Removes the matching switch from ARGV.
54 55 56 |
# File 'lib/nuggets/argv/option_mixin.rb', line 54 def switch!(*args) !!(__key(*args) { |key| delete(key) }) end |