Module Arguable
In: lib/optparse.rb

Extends command line arguments array (ARGV) to parse itself.

Methods

extend_object   getopts   new   options   options=   order!   parse!   permute!  

Public Class methods

Initializes instance variable.

[Source]

      # File lib/optparse.rb, line 1759
1759:     def self.extend_object(obj)
1760:       super
1761:       obj.instance_eval {@optparse = nil}
1762:     end

[Source]

      # File lib/optparse.rb, line 1763
1763:     def initialize(*args)
1764:       super
1765:       @optparse = nil
1766:     end

Public Instance methods

Substitution of getopts is possible as follows. Also see OptionParser#getopts.

  def getopts(*args)
    ($OPT = ARGV.getopts(*args)).each do |opt, val|
      eval "$OPT_#{opt.gsub(/[^A-Za-z0-9_]/, '_')} = val"
    end
  rescue OptionParser::ParseError
  end

[Source]

      # File lib/optparse.rb, line 1752
1752:     def getopts(*args)
1753:       options.getopts(self, *args)
1754:     end

Actual OptionParser object, automatically created if nonexistent.

If called with a block, yields the OptionParser object and returns the result of the block. If an OptionParser::ParseError exception occurs in the block, it is rescued, a error message printed to STDERR and nil returned.

[Source]

      # File lib/optparse.rb, line 1711
1711:     def options
1712:       @optparse ||= OptionParser.new
1713:       @optparse.default_argv = self
1714:       block_given? or return @optparse
1715:       begin
1716:         yield @optparse
1717:       rescue ParseError
1718:         @optparse.warn $!
1719:         nil
1720:       end
1721:     end

Sets OptionParser object, when opt is false or nil, methods OptionParser::Arguable#options and OptionParser::Arguable#options= are undefined. Thus, there is no ways to access the OptionParser object via the receiver object.

[Source]

      # File lib/optparse.rb, line 1694
1694:     def options=(opt)
1695:       unless @optparse = opt
1696:         class << self
1697:           undef_method(:options)
1698:           undef_method(:options=)
1699:         end
1700:       end
1701:     end

Parses self destructively in order and returns self containing the rest arguments left unparsed.

[Source]

      # File lib/optparse.rb, line 1727
1727:     def order!(&blk) options.order!(self, &blk) end

Parses self destructively and returns self containing the rest arguments left unparsed.

[Source]

      # File lib/optparse.rb, line 1739
1739:     def parse!() options.parse!(self) end

Parses self destructively in permutation mode and returns self containing the rest arguments left unparsed.

[Source]

      # File lib/optparse.rb, line 1733
1733:     def permute!() options.permute!(self) end

[Validate]