Top Level Namespace

Includes:
FileUtils

Defined Under Namespace

Modules: Enumerable, JSON, Kernel, Mack Classes: Class, Date, DateTime, Exception, JavascriptGenerator, Object, Range, Regexp, Struct, Symbol, Time

Instance Method Summary collapse

Instance Method Details

#go(s, args = ARGV) ⇒ Object

Parses the argument array args, according to the pattern s, to retrieve the single character command line options from it. If s is ‘xy:’ an option ‘-x’ without an option argument is searched, and an option ‘-y foo’ with an option argument (‘foo’).

An option hash is returned with all found options set to true or the found option argument.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/gems/json_pure-1.1.3/bin/prettify_json.rb', line 15

def go(s, args = ARGV)
  b, v = s.scan(/(.)(:?)/).inject([{},{}]) { |t,(o,a)|
    t[a.empty? ? 0 : 1][o] = a.empty? ? false : nil
    t
  }
  while a = args.shift
    a !~ /\A-(.+)/ and args.unshift a and break
    p = $1
    until p == ''
      o = p.slice!(0, 1)
      if v.key?(o)
        v[o] = if p == '' then args.shift or break 1 else p end
        break
      elsif b.key?(o)
        b[o] = true
      else
        args.unshift a
        break 1
      end
    end and break
  end
  b.merge(v)
end