Skip to content

Commit

Permalink
replace delete_if with select
Browse files Browse the repository at this point in the history
to avoid modifying the original array, which prevents issues with frozen arrays,
fixes #161 "FrozenError - can't modify frozen Array"
  • Loading branch information
alexskr committed Sep 26, 2024
1 parent 8d8f576 commit 16d50db
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions helpers/slices_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ def filter_for_slice(obj)

slice = current_slice()

if obj.is_a?(Enumerable)
if obj.first.is_a?(LinkedData::Models::Ontology)
obj.delete_if {|o| !slice.ontology_id_set.include?(o.id.to_s)}
end
if obj.is_a?(Enumerable) && obj.first.is_a?(LinkedData::Models::Ontology)
obj = obj.select { |o| slice.ontology_id_set.include?(o.id.to_s) }
end
obj
end
Expand All @@ -35,4 +33,4 @@ def current_slice_acronyms
end
end

helpers Sinatra::Helpers::SlicesHelper
helpers Sinatra::Helpers::SlicesHelper

0 comments on commit 16d50db

Please sign in to comment.