Hoping someone might be able to throw me a few clues on this one.
I’m working with lists of names a User (current_user) manages lists of
names, some male some female (scoped on m or f in gender), it’s all set
up such that I can do things like this - all working out fine.
current_user.names.male
(returns a list of the current users male names, pretty standard stuff I
believe).
a Name has the following attributes
given:string
gender:string
postion:integer
user_id:integer
What I’d like to do next is a little scary for me but I’m sure possible,
it is list comparison.
Basically for any given name, I’d like a method that returns other names
from other users lists where they have that given name in the list
(phew what a mouthful, not sure if that’s explained correctly, I think
so).
For example, I’d like to do this.
given user Bob has a list of male names like this
robert
martin
frank
harry
and user Sally has a list of male names like this
keith
harry
paul
name = User.find_by_username(‘Bob’).names.first
=> ‘robert’
what I’d like is a method like this
name.get_other_users_names
which would return nil as no other users have ‘robert’
however
name = User.find_by_username(‘Bob’).names.last
=> ‘harry’
name.get_other_users_names
This should return keith and paul from Sally’s list.
sorry for the verbose message.
Confused if I should start with a class or instance method for starters!