Articles Feed

Authors

Categories

Unrubify

by: paul | December 19th, 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 unrubify 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  

Any suggestions on improvements please let me know!

2 Responses to “Unrubify”

  1. Mark Van Holstyn Says:
    require 'active_support' "this_is_a_word".camelize # => "ThisIsAWord" "this_is_a_word".camelize(:lower) # => "thisIsAWord"
  2. Paul W Pagel Says:
    Thank you!!! I thought it should be there somewhere, but couldn't find it.

Leave a Reply

#