Blender 2.8 - Object index pass in Eevee
In 2.8, Cycles there is something called the cryptomatte node. Unfortunately, at the time of writing this, it is not implemented for Eevee.

I found a solution by creating view layers, then evaluating the depth in both. View layers are like 2.79's render layers, so you can exclude objects from being rendered in each.

Next, I evaluated depth in both view layers. Since one of the view layers is missing the object, you can use a greater than or lesser node to create a mask.

Here's a video on view layers: https://youtu.be/BBuD64KhxeY?t=1502

I imagine 2.8 Eevee will gain cryptomatte in the future.