Module OptionParser::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 1698
1698:     def self.extend_object(obj)
1699:       super
1700:       obj.instance_eval {@optparse = nil}
1701:     end

[Source]

      # File lib/optparse.rb, line 1702
1702:     def initialize(*args)
1703:       super
1704:       @optparse = nil
1705:     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 1691
1691:     def getopts(*args)
1692:       options.getopts(self, *args)
1693:     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 1650
1650:     def options
1651:       @optparse ||= OptionParser.new
1652:       @optparse.default_argv = self
1653:       block_given? or return @optparse
1654:       begin
1655:         yield @optparse
1656:       rescue ParseError
1657:         @optparse.warn $!
1658:         nil
1659:       end
1660:     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 1633
1633:     def options=(opt)
1634:       unless @optparse = opt
1635:         class << self
1636:           undef_method(:options)
1637:           undef_method(:options=)
1638:         end
1639:       end
1640:     end

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

[Source]

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

[Validate]