Class: Argv
Overview
— an argument parser
Defined Under Namespace
Modules: Etest
Instance Attribute Summary collapse
-
#files ⇒ Object
readonly
Returns the value of attribute files.
Instance Method Summary collapse
-
#initialize(argv) ⇒ Argv
constructor
A new instance of Argv.
- #method_missing(sym, *args, &block) ⇒ Object
Methods inherited from Hash
#delete_multi, #insp, #inspect, #slop!, #sloppy?
Methods included from Hash::EnsureKeys
Methods included from Hash::Extract
Methods included from Hash::Compact
Methods included from Hash::Extras
#delete_all, #hmap, included, #select_entries
Methods included from Hash::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
#files ⇒ Object (readonly)
Returns the value of attribute files.
12 13 14 |
# File 'lib/vex/base/argv.rb', line 12 def files @files end |