Ruby on Rails uncapitalize first letter

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

    There is no real inverse of capitalize, but I think underscore comes close.

    "CoolCat".underscore  #=> "cool_cat"
    "cool_cat".capitalize #=> "Cool_cat"
    "cool_cat".camelize   #=> "CoolCat"
    

    Edit: underscore is of course the inverse of camelize, not capitalize.

提交回复
热议问题