Insert _at_ index, rather than before

Inserting at the right index places new item *before* the index, so no
need to decrement and then insert, since `insert` takes care of shifting
down elements of the array.
This commit is contained in:
Brian Cain 2019-08-28 14:11:25 -07:00
parent 5400af7a4a
commit c1f0bd638d
No known key found for this signature in database
GPG Key ID: 9FC4639B2E4510A0
1 changed files with 0 additions and 1 deletions

View File

@ -74,7 +74,6 @@ module Vagrant
idx = 0 idx = 0
if options[:before] if options[:before]
idx = final_provs.each_with_index.map { |(p,o), i| i if o[:name].to_s == options[:before] }.reject(&:nil?).first idx = final_provs.each_with_index.map { |(p,o), i| i if o[:name].to_s == options[:before] }.reject(&:nil?).first
idx -= 1 unless idx == 0
final_provs.insert(idx, [p, options]) final_provs.insert(idx, [p, options])
elsif options[:after] elsif options[:after]
idx = final_provs.each_with_index.map { |(p,o), i| i if o[:name].to_s == options[:after] }.reject(&:nil?).first idx = final_provs.each_with_index.map { |(p,o), i| i if o[:name].to_s == options[:after] }.reject(&:nil?).first