Calling a method in a gsub?

gsub takes a block so you can do something like this:

  string.gsub(regexp) {|x, y, z| output(x, y, z) }

Not sure why your previous expression didn't work between rails and irb though... Are you using different ruby versions between the two environments?