Reputation: 1104
I have an array and I want to remove some elements. I tried this but it doesn't work:
@restaurants.each_with_index do |restaurant, i|
if (restaurant.stars > 3) @restaurants.slice!(i) end
end
How can I do it?
Upvotes: 0
Views: 202
Reputation: 5410
If restaurants is an array you can use pop, e.g.
a = [ "a", "b", "c", "d" ]
a.pop #=> "d"
a.pop(2) #=> ["b", "c"]
a #=> ["a"]
Upvotes: 0