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:

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

If you have any suggestions, please let me know!