Ruby on Rails: Converting SomeWordHere to some word here
The methods underscore and humanize are designed for conversions between tables, class/package names, etc. You are better off using your own code to do the replacement to avoid surprises. See comments.
"SomeWordHere".underscore => "some_word_here"
"SomeWordHere".underscore.humanize => "Some word here"
"SomeWordHere".underscore.humanize.downcase => "some word here"
Converting camel case to underscore case in ruby
Rails' ActiveSupport
adds underscore to the String using the following:
class String
def underscore
self.gsub(/::/, '/').
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
gsub(/([a-z\d])([A-Z])/,'\1_\2').
tr("-", "_").
downcase
end
end
Then you can do fun stuff:
"CamelCase".underscore
=> "camel_case"
Related Topics
Grit's Clone Method Is Undefined
Test (With Rspec) a Controller Outside of a Rails Environment
How to Pass Content to Jekyll Default Converter After Custom Conversion
How Does Count Method Works in Ruby
Ruby: "If !Object.Nil" or "If Object"
How to Use Headless Chrome with Capybara and Selenium
Yaml::Load Raises Undefined Class/Module Error
Why Does the Break Statement in Ruby Behave Differently When Using Proc.New V. the Ampersand Sign
Ruby Installation (2.2.2) Fails in MACos Big Sur
Importing CSV Data into Rails App, Using Something Other Then the Association "Id"
How to Create a Custom Method for the Rails Console
More Concise Version of Max/Min Without the Block
Ruby Outputting to the Same Line as the Previous Output
Monitor Ruby Processes with Monit
Can You 'Require' Ruby File in Irb Session, Automatically, on Every Command