Module: Arg0::Console
- Defined in:
- lib/arg0.rb
Class Method Summary collapse
- .keyring ⇒ Object
- .switch?(switch_name) ⇒ Boolean
- .value(switch_name) ⇒ Object
- .value_for(switch_name) ⇒ Object (also: values)
Class Method Details
.keyring ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/arg0.rb', line 37 def self.keyring key_vals = {} ARGV.each {|arg| last_key = key_vals.keys.last if arg.match(/^-.*/) key_vals[arg] = true elsif key_vals[last_key] == true key_vals[last_key] = arg else key_vals[arg] = :data end } key_vals end |
.switch?(switch_name) ⇒ Boolean
9 10 11 12 13 |
# File 'lib/arg0.rb', line 9 def self.switch?(switch_name) ! [switch_name].flatten.select {|switch| ARGV.include? switch }.empty? end |
.value(switch_name) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/arg0.rb', line 28 def self.value(switch_name) ARGV.each_with_index {|arg, index| if [switch_name].flatten.include? arg return ARGV[index + 1] end } nil end |
.value_for(switch_name) ⇒ Object Also known as: values
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/arg0.rb', line 15 def self.value_for(switch_name) values = [] ARGV.each_with_index {|arg, index| if [switch_name].flatten.include? arg values += [ARGV[index + 1]] end } values.delete nil values end |