I have something like so:
@users_x = returns 0 or more records with (id, user_id, etc...)
@users_y = returns 0 or more records with (id, user_id, etc...)
@users_z = returns 0 or more records with (id, user_id, etc...)
What I’m interested is user_ids. I want to obtain a list of user_id’s for @users_x + @user_y while maintaining the order. And then take the user_ids in @users_z and subtract that from the combined list (x+y). In the end getting a list of user_ids.
How can I pull this off w ruby + rails? Thx
Something like
(@users_x.collect(&:user_id) + @users_y.collect(&:user_id)) – @users_z.collect(&:user_id)
should do the trick. You might want to toss a uniq in there if you don’t want there to be duplicates if an id occurs in both @users_x and @users_y