Ruby on Rails: Converting “SomeWordHere” to “some word here”

前端 未结 4 1073
夕颜
夕颜 2021-01-08 00:29

I know you can do something like:

\"SomeWordHere\".underscore.gsub(\"_\", \" \") 

to get \"some word here\".

I thought that might

4条回答
  •  执念已碎
    2021-01-08 00:30

    alt text

    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"
    

提交回复
热议问题