My Ruby query is really slow. I'm looking for a faster way to select items that belong to two arrays

`listA` is a list of objectA with the attribute `name`

`listB` is a list of objectB with the attribute `name`

There can be multiple items in `listA` that all have the same `name`, but nothing in `listB` with the same `name`. There are also items in `listA` whose `name`s are not in `listB`. I want a function (loop) to return all the items in `listA` where their `name` is in `listB`.

This is my current solution, but it's too slow. How can I make it faster ?

```
z = 0
new = []
while z < listB.length 
    hold = listA.select{|obj| obj.name == listB[z].name}
    new += hold
    z += 1
end

```