(g)sub with Hash replacement

Since 1.9.2 Ruby supports a Hash as second argument to gsub and sub to give replacements based on the individual match.
I guess there is a better way than may implementation, but at least the gsub-part works pretty well.

Documentation is http://www.ruby-doc.org/core-1.9.2/String.html#method-i-sub and http://www.ruby-doc.org/core-1.9.2/String.html#method-i-gsub