Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby on Rails uncapitalize first letter

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 that does the opposite of capitalize, i.e., uncapitalize or decapitalize?

like image 998
ma11hew28 Avatar asked Dec 17 '10 19:12

ma11hew28


People also ask

How do you Upcase the first letter in Ruby?

Ruby | String capitalize() Method capitalize is a String class method in Ruby which is used to return a copy of the given string by converting its first character uppercase and the remaining to lowercase.

How do you lowercase a string in Ruby?

In Ruby, we use the downcase method to convert a string to lowercase. This method takes no parameters and returns the lowercase of the string that calls it. It returns the original string if no changes are made. Note: This method does not affect the original string.

What is Upcase in Ruby?

Symbol#upcase() : upcase() is a Symbol class method which returns the uppercase representation of the symbol object.


1 Answers

There is also:

"coolat_cat".camelize(:lower) # => "coolCat" 
like image 190
tfischbach Avatar answered Oct 06 '22 06:10

tfischbach