### In Files

- ropt.rb

### Parent

Object

### Methods

- new
- parse
- set_valopt

### Files

- wxruby2.lib

### Class Index

Quicksearch

- Wx
- Wx::AcceleratorTable
- Wx::Animation
- Wx::App
- Wx::ArtProvider
- Wx::AuiNotebook
- Wx::Bitmap
- Wx::BusyCursor
- Wx::CheckListBox
- Wx::Choice
- Wx::ClientDC
- Wx::Clipboard
- Wx::Colour
- Wx::ComboBox
- Wx::CommandEvent
- Wx::ControlWithItems
- Wx::DC
- Wx::Event
- Wx::EvtHandler
- Wx::Font
- Wx::Grid
- Wx::HelpController
- Wx::HelpControllerHelpProvider
- Wx::HelpProvider
- Wx::HtmlHelpController
- Wx::HtmlWindow
- Wx::Icon
- Wx::IconBundle
- Wx::Image
- Wx::ImageList
- Wx::KeywordConstructor
- Wx::KeywordConstructor::ClassMethods
- Wx::ListBox
- Wx::ListCtrl
- Wx::Locale
- Wx::MediaCtrl
- Wx::Menu
- Wx::MenuItem
- Wx::Notebook
- Wx::Object
- Wx::PaintDC
- Wx::Point
- Wx::PreviewFrame
- Wx::Rect
- Wx::RichTextCtrl
- Wx::SimpleHelpProvider
- Wx::Size
- Wx::Sizer
- Wx::Sound
- Wx::StandardPaths
- Wx::TextCtrl
- Wx::TextUrlEvent
- Wx::Timer
- Wx::ToolBar
- Wx::ToolBarTool
- Wx::TreeCtrl
- Wx::Window
- Wx::XmlResource
- Rumix
- Rumix::Application
- Rumix::Config
- Rumix::Registry
- Rumix::Widget
- Rumix::Widget::CheckOptionPanel
- Rumix::Widget::OptionItem
- Rumix::Widget::OptionPanel
- Rumix::Widget::RadioOptionPanel
- Rumix::Widget::TitleText
- ROpt
- ROpt::ArgumentParser
- ROpt::ParseResult
- Uconv
- Uconv::Error
- Enumerable
- File
- Ini
- Kernel
- Module
- Object
- Pathname
- WxConstructor
- WxRubyStyleAccessors

No matching classes.

# ROpt::ArgumentParser

### Public Class Methods

new(*parse_rule_args, &missing_proc) click to toggle source

(Not documented)

    # File ropt.rb, line 23
        def initialize(*parse_rule_args, &missing_proc)
          @boolopts = {}
          @valopts = {}
          @multival_opts_set = {}
          @missing_proc = missing_proc || proc { false; }

          single_options = parse_rule_args.shift || ""
          single_options.scan(%r".:{0,2}") do |optspec|
            if optspec.size == 1
              @boolopts[optspec] = nil
            else
              opt = optspec[0, 1]
              @valopts[opt] = case optspec.size
                              when 2; nil
                              when 3
                                @multival_opts_set[opt] = true
                                nil
                              else; raise(InvalidParseRuleError,
                                          single_options)
                              end
            end
          end if single_options

          options = parse_rule_args
          options.each do |arg|
            unless arg =~ %r"\A([^:]+)(:{0,2})"
              raise(InvalidParseRuleError, arg)
            end
            opt = $~[1]
            corons = $~[2].size
            default_val = $~.post_match
            if corons == 0
              @boolopts[opt] = nil
            else
              @valopts[opt] = case $2.size
                              when 1; default_val.empty?() ? nil : default_val
                              when 2
                                @multival_opts_set[opt] = true
                                nil
                              else; raise(InvalidParseRuleError, arg)
                              end
            end
          end
        end

### Public Instance Methods

parse(argv) click to toggle source

Based on getopts.rb

    # File ropt.rb, line 69
        def parse(argv)
          argv = argv.dup
          boolopts = @boolopts.dup
          valopts = @valopts.dup
          @multival_opts_set.each_key { |opt|
            valopts[opt] = []
          }
          c = 0
          while arg = argv.shift
            case arg
            when /\A--(.*)/
              if $1.empty?                  # xinit -- -bpp 24
                break
              end

              opt, val = $1.split('=', 2)

              if opt.size == 1
                argv.unshift arg
                return nil
              elsif valopts.key? opt                # imclean --src +trash
                optval = (val || argv.shift) or return(nil)
                set_valopt(valopts, opt, optval)
              elsif boolopts.key? opt               # ruby --verbose
                boolopts[opt] = true
              else
                argv.unshift(val) if val
                @missing_proc[opt, argv] or return(nil)
              end

              c += 1
            when /\A-(.+)/
              opts = $1

              until opts.empty?
                opt = opts.slice!(0, 1)

                if valopts.key? opt
                  val = opts

                  if val.empty?                     # ruby -e 'p $:'
                    optval = argv.shift or return(nil)
                    set_valopt(valopts, opt, optval)
                  else                              # cc -ohello ...
                    set_valopt(valopts, opt, val)
                  end

                  c += 1
                  break
                elsif boolopts.key? opt
                  boolopts[opt] = true              # ruby -h
                  c += 1
                else
                  opts.empty? or argv.unshift(opts)
                  @missing_proc[opt, argv] or return(nil)
                  opts = opts.equal?(argv[0]) ? argv.shift.dup : ""
                end
              end
            else
              argv.unshift arg
              break
            end
          end

          opthash = boolopts
          opthash.update(valopts)
          ParseResult.new(argv, opthash)
        end

set_valopt(valopts, opt, val) click to toggle source

(Not documented)

    # File ropt.rb, line 138
        def set_valopt(valopts, opt, val)
          if @multival_opts_set[opt]
            valopts[opt] << val
          else
            valopts[opt] = val
          end
        end

Disabled; run with $DEBUG to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.