From 63961205fc9872531bf78a698a02ab15a9df3dce Mon Sep 17 00:00:00 2001 From: max lin Date: Sat, 11 Mar 2023 03:02:14 +0800 Subject: [PATCH] Rewrite `and` operator with `#index` --- lib/json_logic/operation.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/json_logic/operation.rb b/lib/json_logic/operation.rb index be8a972..a39a4f6 100644 --- a/lib/json_logic/operation.rb +++ b/lib/json_logic/operation.rb @@ -93,8 +93,8 @@ class Operation '!!' => ->(v, d) { v[0].truthy? }, 'or' => ->(v, d) { v.find(&:truthy?) || v.last }, 'and' => ->(v, d) { - result = v.find(&:falsy?) - result.nil? ? v.last : result + idx = v.index(&:falsy?) + idx.nil? ? v.last : v[idx] }, '?:' => ->(v, d) { LAMBDAS['if'].call(v, d) }, '>' => ->(v, d) { v.map(&:to_f).each_cons(2).all? { |i, j| i > j } },