Release a Ruby Gem with OTP code

I used to just be able to publish a new release of a ruby gem with rake release, but now that I have added 2FA to ruby gems that command doesn’t work any more.

Now what I need to do is run:

gem build discourse_api.gemspec

then

gem push discourse_api-0.38.0.gem

It will then prompt for my OTP code:

Pushing gem to https://rubygems.org...
You have enabled multi-factor authentication. Please enter OTP code.
Code:   ******

And once I hit enter it will then say:

Successfully registered gem: discourse_api (0.38.0)

*.gem should be in your .gitignore file so that you don’t commit it.