In case ruby can’t find OpenSSL 3 headers, use this way.
brew install ruby-install ruby-install ruby 3.1.4 -- --with-openssl-dir=$(brew --prefix openssl)