Un–Rubify

Un–Rubify

Paul Pagel
Paul Pagel

December 19, 2007

Often times while writing meta programming code, I am using the eval function and doing manipulation on method/class/variable names.

Today I needed to un–Rubify a name. I haven’t seen this done regularly, and unfortunately there is no fun Rails method to do it (there is one for Rubifying a string).

So, here is my attempt at it, for anyone trying to solve the same problem:


def unrubify(sentence)
		sentence.capitalize!
		sentence.gsub!(/_(.)/) { $1.upcase }
		return sentence
end

If you have any suggestions, please let me know!