Updating Ruby to 3.1.4 and relevant code to follow new Rubocop rules.
Related to performance#582 (closed)