From c39e01ceb7faf65edb23fb0f294702428a0a7fce Mon Sep 17 00:00:00 2001 From: nametoolong Date: Sat, 21 Jan 2023 14:16:20 +0800 Subject: [PATCH] Fix common prefix calculation --- lib/cache_crispies/json_builder.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/cache_crispies/json_builder.rb b/lib/cache_crispies/json_builder.rb index c801242..8399355 100644 --- a/lib/cache_crispies/json_builder.rb +++ b/lib/cache_crispies/json_builder.rb @@ -57,11 +57,13 @@ def write_attribute(json_writer, attribute) private def common_prefix_length(array1, array2) - (0...[array1.length, array2.length].min).each do |i| + shorter_length = [array1.length, array2.length].min + + (0...shorter_length).each do |i| return i if array1[i] != array2[i] end - array1.length + shorter_length end end end