summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNaoki Mizuno <nigorojr@gmail.com>2015-09-08 14:23:31 -0400
committerNaoki Mizuno <nigorojr@gmail.com>2015-09-08 14:23:31 -0400
commitebe678b1639654604b3e54b08ca710c38682b83e (patch)
tree518e03e2cb6258dcb9762a3b6b407f1e3e893d30
parentf8012062596783e0e518e3f11d94bb2916a5f84f (diff)
downloadslop-ebe678b1639654604b3e54b08ca710c38682b83e.tar.gz
Use each_with_index for looping over arguments
-rw-r--r--lib/slop/parser.rb16
1 files changed, 3 insertions, 13 deletions
diff --git a/lib/slop/parser.rb b/lib/slop/parser.rb
index d1410a3..553c2ff 100644
--- a/lib/slop/parser.rb
+++ b/lib/slop/parser.rb
@@ -62,8 +62,9 @@ module Slop
# arguments (plus the arg if necessary)
# delete argument first so that it doesn't mess up the index
if opt.expects_argument?
- index = arg_index(flag, arg)
- arguments.delete_at(index) if !index.nil?
+ arguments.each_with_index do |argument, i|
+ arguments.delete_at(i + 1) if argument == flag
+ end
end
arguments.delete(flag)
end
@@ -120,16 +121,5 @@ module Slop
def matching_option(flag)
options.find { |o| o.flags.include?(flag) }
end
-
- # Returns the index of the argument corresponding to a flag.
- def arg_index(flag, arg)
- flag_index = arguments.index(flag)
- return nil if flag_index.nil?
-
- arg_index = arguments[flag_index..-1].index(arg)
- return nil if arg_index.nil?
-
- flag_index + arg_index
- end
end
end