The shape of the block String#gsublooks like you need:
s = "Today it is 25C and tomorrow 27 C."
re = /(\d+\s?C)/
s.gsub(re) {|c| "%dF" % (c.to_f * 9.0 / 5.0 + 32.0).round }
I lost the degree symbol (I used Ruby 1.8.7, which is not very suitable for Unicode), but hopefully this should be enough to see what might be possible.
source
share