Lohith MV Lohith MV - 1 year ago 233
Ruby Question

Converting string from snake_case to CamelCase in Ruby

I am trying to convert a name from snake case to camel case. Are there any built-in methods?



(I have a string
I want to convert that to model

Answer Source

If you're using Rails, String#camelize is what you're looking for.

  "active_record".camelize                # => "ActiveRecord"
  "active_record".camelize(:lower)        # => "activeRecord"

If you want to get an actual class, you should use String#constantize on top of that.