Is there a ready-made function that converts strings into camel cases for strings separated by underscores?
I would like something like this:
"CamelCaseString".to_underscore
return "camel_case_string"
.
Is there a ready-made function that converts strings into camel cases for strings separated by underscores?
I would like something like this:
"CamelCaseString".to_underscore
return "camel_case_string"
.
Rails' ActiveSupport adds underscore to the String class using this code:
class String
def underscore
self.gsub(/::/, '/').
gsub(/([A-Z]+)([A-Z][a-z])/,'_').
gsub(/([a-z\d])([A-Z])/,'_').
tr("-", "_").
downcase
end
end
Ready:
"CamelCase".underscore
=> "camel_case"