Module: Spruz::GO

### Home Classes Methods

### In Files

- lib/spruz/go.rb

### Methods

- #go

### Files

- README.rdoc

### Class/Module Index

Quicksearch

- Spruz
- Spruz::Attempt
- Spruz::Bijection
- Spruz::Blank
- Spruz::Blank::Array
- Spruz::Blank::FalseClass
- Spruz::Blank::Hash
- Spruz::Blank::NilClass
- Spruz::Blank::Numeric
- Spruz::Blank::Object
- Spruz::Blank::String
- Spruz::Blank::TrueClass
- Spruz::CountBy
- Spruz::DeepDup
- Spruz::FileBinary
- Spruz::FileBinary::ClassMethods
- Spruz::FileBinary::Constants
- Spruz::Full
- Spruz::GO
- Spruz::Generator
- Spruz::HashSymbolizeKeysRecursive
- Spruz::HashUnion
- Spruz::Limited
- Spruz::LinesFile
- Spruz::LinesFile::LineExtension
- Spruz::Memoize
- Spruz::Minimize
- Spruz::ModuleGroup
- Spruz::Null
- Spruz::Once
- Spruz::P
- Spruz::PartialApplication
- Spruz::RangePlus
- Spruz::Round
- Spruz::SecureWrite
- Spruz::Shuffle
- Spruz::StringCamelize
- Spruz::StringUnderscore
- Spruz::StringVersion
- Spruz::StringVersion::Version
- Spruz::Subhash
- Spruz::TimeDummy
- Spruz::TimeDummy::ClassMethods
- Spruz::ToProc
- Spruz::UniqBy
- Spruz::Write
- Array
- Enumerable
- File
- Float
- Hash
- IO
- IRB
- Integer
- Method
- Module
- Object
- Proc
- Range
- String
- Symbol
- Time

No matching classes.

# Spruz::GO

### Public Instance Methods

go(s, args = ARGV) click to toggle source

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.

    # File lib/spruz/go.rb, line 12
    def go(s, args = ARGV)
      b,v = s.scan(/(.)(:?)/).inject([{},{}]) { |t,(o,a)|
        a = a == ':'
        t[a ? 1 : 0][o] = a ? nil : false
        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)
            if p == '' then
              v[o] = args.shift or break 1
            else
              v[0] = 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

[Validate]

Generated with the Darkfish Rdoc Generator 2.