I have an array called @friend_comparisons that is populated with a number of user objects. Then I sort the array using the following:
@friend_comparisons.sort! { |a,b| b.completions.where(:list_id => @list.id).first.counter <=> a.completions.where(:list_id => @list.id).first.counter }
This is sorting the array using a specific counter associated with each user (the features of which are not important for the question).
I want to find out how many user objects in the array have a counter that is greater than a certain number (say 5). How to do it?
This is how I solve the problem now:
@friends_rank = 1 for friend in @friend_comparisons do if friend.completions.where(:list_id => @list.id).first.counter > @user_restaurants.count @friends_rank = @friends_rank + 1 end end
ruby-on-rails-3
Alex
source share