I'm experiencing a strange issue with a ruby function I wrote to remove unwanted items from a hash created by parsing a JSON string. The function will return what I am expecting when I have pry statements included in the function as seen at the bottom of this post. When I remove the pry statements the function returns something else. I'm not really sure why that would be the case and figured I'd ask here while I try to figure out an alternative solution to my problem.
Below, slides is a string of space separated integers such that slides.split(' ') returns an array of integers. Slide groups is a parsed JSON hash. If requested I can provide a file with the JSON hash, but it was getting frustrating to try and enter it here. I don't think it is necessary to see the hash since it seems the issue lies with pry and the effect it is having on the function.
def selected_slides_and_groups
selected_slide_ids = slides.split(' ')
slide_groups = master_presentation.slide_groups
slide_groups.each do |slide_group|
delete_slides_from_group(slide_group, selected_slide_ids)
end
end
def delete_slides_from_group(slide_group, selected_slide_ids)
binding.pry
slide_group[:content].delete_if do |item|
if item[:type] == 'group'
delete_slides_from_group(item, selected_slide_ids)
elsif selected_slide_ids.include? item[:id]
next
else
true
end
end
binding.pry
end
Methods in Ruby return last evaluated value (unless specified otherwise) and binding.pry
call returns nil
.