Class: Argv

Inherits:
Hash show all
Defined in:
lib/vex/base/argv.rb

Overview

— an argument parser

Defined Under Namespace

Modules: Etest

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Hash

#delete_multi, #insp, #inspect, #slop!, #sloppy?

Methods included from Hash::EnsureKeys

#keys?

Methods included from Hash::Extract

#extract, #extract!

Methods included from Hash::Compact

#compact, #compact!

Methods included from Hash::Extras

#delete_all, #hmap, included, #select_entries

Methods included from Hash::Cross

#cross

Constructor Details

#initialize(argv) ⇒ Argv

Returns a new instance of Argv.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/vex/base/argv.rb', line 14

def initialize(argv)
  @files = []
  argv = argv.dup
  while arg = argv.shift do
    if !(option = option?(arg))
      files.push(arg)
    elsif arg =~ /^--no-/
      set option, false
    elsif argv.first.nil? || option?(argv.first)
      set option, true
    else
      set option, argv.shift
    end
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object



3
4
5
6
7
8
9
10
# File 'lib/vex/base/argv.rb', line 3

def method_missing(sym, *args, &block)
  return fetch(sym) if args.empty? && !block_given? && key?(sym)
  if sym.to_s =~ /(.*)\?$/
    return self[$1.to_sym]
  end
  
  super
end

Instance Attribute Details

#filesObject (readonly)

Returns the value of attribute files.



12
13
14
# File 'lib/vex/base/argv.rb', line 12

def files
  @files
end