Module: Clip
- Defined in:
- lib/clip.rb
Defined Under Namespace
Classes: Flag, IllegalConfiguration, Option, Parser
Constant Summary collapse
- VERSION =
"0.0.6"- HASHER_REGEX =
/^--?\w+/
Class Method Summary collapse
-
.hash(argv = ARGV.dup, values = []) ⇒ Object
Turns ARGV into a hash.
-
.reset_hash! ⇒ Object
Clear the cached hash value.
Class Method Details
.hash(argv = ARGV.dup, values = []) ⇒ Object
Turns ARGV into a hash.
my_clip_script -c config.yml # Clip.hash == { 'c' => 'config.yml' }
my_clip_script command -c config.yml # Clip.hash == { 'c' => 'config.yml' }
my_clip_script com -c config.yml -d # Clip.hash == { 'c' => 'config.yml' }
my_clip_script -c config.yml --mode optimistic
# Clip.hash == { 'c' => 'config.yml', 'mode' => 'optimistic' }
346 347 348 349 350 351 352 353 354 |
# File 'lib/clip.rb', line 346 def self.hash(argv = ARGV.dup, values = []) @hash ||= begin argv.shift until argv.first =~ HASHER_REGEX or argv.empty? while argv.first =~ HASHER_REGEX and argv.size >= 2 do values += [argv.shift.sub(/^--?/, ''), argv.shift] end Hash[*values] end end |
.reset_hash! ⇒ Object
Clear the cached hash value. Probably only useful for tests, but whatever.
358 |
# File 'lib/clip.rb', line 358 def Clip.reset_hash!; @hash = nil end |