Module: Nuggets::Argv::OptionMixin

Defined in:
lib/nuggets/argv/option_mixin.rb

Instance Method Summary collapse

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.



46
47
48
# File 'lib/nuggets/argv/option_mixin.rb', line 46

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.



66
67
68
# File 'lib/nuggets/argv/option_mixin.rb', line 66

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).



36
37
38
# File 'lib/nuggets/argv/option_mixin.rb', line 36

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.



55
56
57
# File 'lib/nuggets/argv/option_mixin.rb', line 55

def switch!(*args)
  !!(__key(*args) { |key| delete(key) })
end