Skip to content

End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

String#capitalize

str.capitalize → new_str
str.capitalize([options]) → new_str

Returns a copy of str with the first character converted to uppercase and the remainder to lowercase.

See String#downcase for meaning of options and use with different encodings.

Example
"hello".capitalize    #=> "Hello"
"HELLO".capitalize    #=> "Hello"
"123ABC".capitalize   #=> "123abc"

Ruby version changes

  1. 3.0
See also #capitalize! #byteslice #bytesize #casecmp also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1