首字母大写

首先,写一个方法。

 

    class String
      def init_caps
        self.tr('-', ' ').split(' ').map { |word| word.chars.first.upcase.to_s + "." }.join
      end
    end

 

示例:

 

"very-important-people".init_caps  # => V.I.P.

 

你可能感兴趣的:(大写)