| Module | Arguable |
| In: |
lib/optparse.rb
|
Extends command line arguments array (ARGV) to parse itself.
Initializes instance variable.
# File lib/optparse.rb, line 1762
1762: def self.extend_object(obj)
1763: super
1764: obj.instance_eval {@optparse = nil}
1765: end
# File lib/optparse.rb, line 1766
1766: def initialize(*args)
1767: super
1768: @optparse = nil
1769: end
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
# File lib/optparse.rb, line 1755
1755: def getopts(*args)
1756: options.getopts(self, *args)
1757: 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.
# File lib/optparse.rb, line 1714
1714: def options
1715: @optparse ||= OptionParser.new
1716: @optparse.default_argv = self
1717: block_given? or return @optparse
1718: begin
1719: yield @optparse
1720: rescue ParseError
1721: @optparse.warn $!
1722: nil
1723: end
1724: 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.
# File lib/optparse.rb, line 1697
1697: def options=(opt)
1698: unless @optparse = opt
1699: class << self
1700: undef_method(:options)
1701: undef_method(:options=)
1702: end
1703: end
1704: end
Parses self destructively in order and returns self containing the rest arguments left unparsed.
# File lib/optparse.rb, line 1730
1730: def order!(&blk) options.order!(self, &blk) end
Parses self destructively and returns self containing the rest arguments left unparsed.
# File lib/optparse.rb, line 1742
1742: def parse!() options.parse!(self) end