| Module | Arguable |
| In: |
lib/optparse.rb
|
Extends command line arguments array (ARGV) to parse itself.
Initializes instance variable.
# File lib/optparse.rb, line 1767
1767: def self.extend_object(obj)
1768: super
1769: obj.instance_eval {@optparse = nil}
1770: end
# File lib/optparse.rb, line 1771
1771: def initialize(*args)
1772: super
1773: @optparse = nil
1774: 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 1760
1760: def getopts(*args)
1761: options.getopts(self, *args)
1762: 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 1719
1719: def options
1720: @optparse ||= OptionParser.new
1721: @optparse.default_argv = self
1722: block_given? or return @optparse
1723: begin
1724: yield @optparse
1725: rescue ParseError
1726: @optparse.warn $!
1727: nil
1728: end
1729: 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 1702
1702: def options=(opt)
1703: unless @optparse = opt
1704: class << self
1705: undef_method(:options)
1706: undef_method(:options=)
1707: end
1708: end
1709: end
Parses self destructively in order and returns self containing the rest arguments left unparsed.
# File lib/optparse.rb, line 1735
1735: 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 1747
1747: def parse!() options.parse!(self) end