Skip to content

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

instance method

String#capitalize

capitalize(*options) → string

Returns a string containing the characters in self; the first character is upcased; the remaining characters are downcased:

Example
s = 'hello World!' # => "hello World!"
s.capitalize       # => "Hello world!"

The casing may be affected by the given options; see Case Mapping.

Related: String#capitalize!.

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.0