summaryrefslogtreecommitdiff
path: root/lib/optparse.rb
diff options
context:
space:
mode:
authorfatkodima <[email protected]>2024-08-05 05:28:01 +0300
committergit <[email protected]>2024-08-05 02:28:12 +0000
commita35d32486242641ccd2ac98d43211343a3712c52 (patch)
treeac670d9f747c64126664be3bef8e4e21f09b1ef6 /lib/optparse.rb
parentcbc40bb130fb52f1990ce1fd41e834a5f3fdbcdd (diff)
[ruby/optparse] Fix parsing array arguments with `:into` option
https://github.com/ruby/optparse/commit/19700e96d8
Diffstat (limited to 'lib/optparse.rb')
-rw-r--r--lib/optparse.rb14
1 files changed, 8 insertions, 6 deletions
diff --git a/lib/optparse.rb b/lib/optparse.rb
index 069c3e436e..d52401a31b 100644
--- a/lib/optparse.rb
+++ b/lib/optparse.rb
@@ -1729,9 +1729,9 @@ XXX
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
@@ -1761,7 +1761,7 @@ XXX
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
@@ -1769,8 +1769,8 @@ XXX
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
@@ -1798,6 +1798,8 @@ XXX
# 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