fix broken `gem` method with non-String arguments. Closes #16709.

This was caused by #15327.