Oh I do hate /usr/ports/UPDATING when they refer you to an entry 3 years prior on how to update the current version of a major revision bump and then you need to dig out and correct the numbers to make it work. So I am just going to down my editing here so I can find more easily.
If you use portmaster, install new ruby, then rebuild all ports that depend on ruby:
cd /usr/ports/lang/ruby31 and Make install
# portmaster -o lang/ruby31 lang/ruby30
# portmaster -R -r ruby-3.1