Lohith MV Lohith MV - 1 year ago 271
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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download