If you can live with it printing "2.0" instead of "2", you can simply do:
"120m 90m".gsub(/(\d+)m/) { "#{$1.to_f / 60.0}h"}
If you need to print it without ".0", you need to check if the number is equally divisible by 60, and if so return $1.to_i / 60instead $1.to_f / 60.0.
Alternatively, you can call to_sin the float and delete .0if the line ends with ".0"
source
share