Ruby on Rails uncapitalize first letter

前端 未结 10 1501
感动是毒
感动是毒 2021-02-03 19:48

I\'m running Rails 2.3.2.

How do I convert \"Cool\" to \"cool\"? I know \"Cool\".downcase works, but is there a Ruby/Rails method

10条回答
  •  情深已故
    2021-02-03 20:17

    There is no inverse of capitalize, but you can feel free to roll your own:

    class String
      def uncapitalize 
        self[0, 1].downcase + self[1..-1]
      end
    end
    

提交回复
热议问题