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 1765
1765:     def self.extend_object(obj)
1766:       super
1767:       obj.instance_eval {@optparse = nil}
1768:     end

[Source]

      # File lib/optparse.rb, line 1769
1769:     def initialize(*args)
1770:       super
1771:       @optparse = nil
1772:     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 1758
1758:     def getopts(*args)
1759:       options.getopts(self, *args)
1760:     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 1717
1717:     def options
1718:       @optparse ||= OptionParser.new
1719:       @optparse.default_argv = self
1720:       block_given? or return @optparse
1721:       begin
1722:         yield @optparse
1723:       rescue ParseError
1724:         @optparse.warn $!
1725:         nil
1726:       end
1727:     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 1700
1700:     def options=(opt)
1701:       unless @optparse = opt
1702:         class << self
1703:           undef_method(:options)
1704:           undef_method(:options=)
1705:         end
1706:       end
1707:     end

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

[Source]

      # File lib/optparse.rb, line 1733
1733:     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 1745
1745:     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 1739
1739:     def permute!() options.permute!(self) end

[Validate]