lib/optparse.rb in optparse-0.5.0 vs lib/optparse.rb in optparse-0.6.0

- old
+ new

@@ -423,11 +423,11 @@ # should be enough to learn how to use this class. # If you have any questions, file a ticket at http://bugs.ruby-lang.org. # class OptionParser # The version string - OptionParser::Version = "0.5.0" + OptionParser::Version = "0.6.0" # :stopdoc: NoArgument = [NO_ARGUMENT = :NONE, nil].freeze RequiredArgument = [REQUIRED_ARGUMENT = :REQUIRED, true].freeze OptionalArgument = [OPTIONAL_ARGUMENT = :OPTIONAL, false].freeze @@ -1113,11 +1113,11 @@ # Officious['version'] = proc do |parser| Switch::OptionalArgument.new do |pkg| if pkg begin - require 'optparse/version' + require_relative 'optparse/version' rescue LoadError else show_version(*pkg.split(/,/)) or abort("#{parser.program_name}: no version found in package #{pkg}") exit @@ -1727,13 +1727,13 @@ throw :terminate, arg unless raise_unknown raise InvalidOption, arg end end begin - opt, cb, *val = sw.parse(rest, argv) {|*exc| raise(*exc)} - val = callback!(cb, 1, *val) if cb - callback!(setter, 2, sw.switch_name, *val) if setter + opt, cb, val = sw.parse(rest, argv) {|*exc| raise(*exc)} + val = callback!(cb, 1, val) if cb + callback!(setter, 2, sw.switch_name, val) if setter rescue ParseError raise $!.set_option(arg, rest) end # short option @@ -1759,20 +1759,20 @@ rescue ParseError throw :terminate, arg unless raise_unknown raise $!.set_option(arg, true) end begin - opt, cb, *val = sw.parse(val, argv) {|*exc| raise(*exc) if eq} + opt, cb, val = sw.parse(val, argv) {|*exc| raise(*exc) if eq} rescue ParseError raise $!.set_option(arg, arg.length > 2) else raise InvalidOption, arg if has_arg and !eq and arg == "-#{opt}" end begin argv.unshift(opt) if opt and (!rest or (opt = opt.sub(/\A-*/, '-')) != '-') - val = callback!(cb, 1, *val) if cb - callback!(setter, 2, sw.switch_name, *val) if setter + val = callback!(cb, 1, val) if cb + callback!(setter, 2, sw.switch_name, val) if setter rescue ParseError raise $!.set_option(arg, arg.length > 2) end # non-option argument @@ -1796,9 +1796,11 @@ end private :parse_in_order # Calls callback with _val_. def callback!(cb, max_arity, *args) # :nodoc: + args.compact! + if (size = args.size) < max_arity and cb.to_proc.lambda? (arity = cb.arity) < 0 and arity = (1-arity) arity = max_arity if arity > max_arity args[arity - 1] = nil if arity > size end