Ruby:扩展String类以将每个单词大写
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Ruby:扩展String类以将每个单词大写相关的知识,希望对你有一定的参考价值。
Don't forget to use require 'directory/name_of_class'
# This helper is opening up core Ruby String class # in order to add a new method to all Strings class String # Ruby has a capitalize method (used below) which capitalizes the # first letter of a string. But in order to capitalize the first # letter of EVERY word we have to write our own. def titleize self.split(' ').collect {|word| word.capitalize}.join(" ") end end
以上是关于Ruby:扩展String类以将每个单词大写的主要内容,如果未能解决你的问题,请参考以下文章