Ruby on Rails uncapitalize first letter

前端 未结 10 1470
感动是毒
感动是毒 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:13

    Try this

    'Cool'.sub(/^([A-Z])/) { $1.tr!('[A-Z]', '[a-z]') }
    

    https://apidock.com/ruby/XSD/CodeGen/GenSupport/uncapitalize

提交回复
热议问题