Unrubify 2

Posted by Paul Pagel Wed, 19 Dec 2007 21:01:00 GMT

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!

Comments

Leave a response

  1. Mark Van Holstyn about 3 hours later:
    require 'active_support'
    "this_is_a_word".camelize # => "ThisIsAWord"
    "this_is_a_word".camelize(:lower) # => "thisIsAWord"
    
  2. Paul W Pagel about 19 hours later:

    Thank you!!! I thought it should be there somewhere, but couldn’t find it.

Comments