I am having trouble translating this into Ruby.
Here is a piece of JavaScript that does exactly what I want to do:
function get_code(str){ return str
"foobar".gsub(/(o+)/){|s|s+'ball'} #=> "fooballbar"