One of my favourite features of Gmail is the ability to bookmark urls to certain messages like this:
https://mail.google.com/mail/#all/124c8f386d41fd3a
What
I was struggling with this too, and then i found the UID is actually the same thing as the Google Message ID.
The UID is an Integer and the Google Message ID is the Hexadecimal version of the that.
Unsure about conversion in ruby, but try this: Converting an integer to a hexadecimal string in Ruby