views:

39

answers:

1

I have an array of users who are friends. Let us call this array:

friends

I then have an array of structs. Each struct has a user object as an attribute (it also has a rank attribute). Here's what the struct class looks like, to add some context:

class Leader < Struct.new(:rank, :user); end

Let us call this array of structs:

all_leaders_plus_rank

I want to compare friends and all_leaders_plus_rank, and add the match from all_leaders_plus_rank to a new array of structs called friendly_leaders.

A: 
friendly_leaders = all_leaders_plus_rank.select do |lpr|
  friends.include?(lpr.user)
end
sepp2k