liveBook · Manning

Capitalize

As explained in The Well-Grounded Rubyist, Fourth Edition

capitalize is a Ruby String method that returns a string with its first character capitalized and the remaining characters lowercased.

capitalize is a Ruby String case transformation: it returns a string with its first character capitalized and the remaining characters lowercased. The original string remains unchanged; capitalize! provides the in-place equivalent. section 8.1.5

>> string = "david"
=> "david"
>> string.capitalize
=> "David"

Try the transformation in an irb-sized example: "david".capitalize returns "David". section 8.1.5

How The Well-Grounded Rubyist, Fourth Edition covers it

How deep it goes
Defines the returned casing and notes the in-place variant, without developing deeper implementation mechanics.
Examples
Uses "david".capitalize to produce "David".
What you can do after
Apply capitalize to produce a newly transformed string, or use capitalize! for in-place transformation.
How it connects
Connects String transformations with case transformations and the bang-method convention.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Well-Grounded Rubyist, Fourth Edition. The section links point to the parts of the book it draws on.