我正在尝试编写一个帮助程序,将字符串从"something_like_this"
翻译成"Something like this"
。 我使用"something_like_this".titlecase
将其转换为"Something Like This"
,但我无法将除首字母外的大写字母全部转换为小写。
我想我需要类似于这样的东西:
def write_sentence
string.titlecase.gsub!(/UPPERCASE-TO-LOWERCASE-EXCEPT-FIRST/)
#that should be something to lowercase everything except the first letter
return string
end
所以在我的看法中,我可以只写string.write_sentence
并确保它返回我想要的内容。有什么想法吗?谢谢!
编辑
我应该提到字符串有时可能只是一个单词,在这种情况下,字符串应该从
"something"
转换为"Something"
。