Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/json_logic/operation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,13 @@ class Operation
v[1]
end,
'if' => ->(v, d) {
v.each_slice(2) do |condition, value|
i = 0
while i < v.length do
condition = v[i]
value = v[i+1]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL: access an out-of-bound index will yield nil instead of an exception.

return condition if value.nil?
return value if condition.truthy?
i += 2
end

nil
Expand Down