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
If you use Ruby Facets, you can lowercase the first letter:
https://github.com/rubyworks/facets/blob/master/lib/core/facets/string/uppercase.rb
There is also:
"coolat_cat".camelize(:lower) # => "coolCat"
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
.
There is an inverse of capitalize
called swapcase
:
"Cool Cat".swapcase #=> "cOOL cAT"