There is a method provided in rails to convert a string to the camel case.
The method is camelize.
By default camelize converts a string to upper camel case. If we don't specify any argument in camelize method, it will convert the given string to upper camel case.
ex:-
2.1.5 :003 > a = "hello_world".camelize
=> "HelloWorld"
If we want to print the string in lower CamelCase(i.e first character in lower case and first character of other Consecutive words in upper case) then we can pass a lower parameter to the camelize method.
ex:-
2.1.5 :002 > "hello_world".camelize(:lower)
=> "helloWorld"
If a string is to be converted to the snake case we can use the underscore method provided by Rails.
The underscore method converts a string to snake case(i.e words seperated with _)
2.1.5 :010 > "HelloWorldTest".underscore
=> "hello_world_test"
0 Comment(s)