Reason #31 •
January 31st, 2026
String#capitalize
Let's have a nice and relaxed Saturday today with String#capitalize. Because sometimes, you just want to capitalize a String and you don't want to remember how to program.
Ruby
"hello world".capitalize # => "Hello world"
JavaScript
const string = "hello world" string.charAt(0).toUpperCase() + string.slice(1) // => "Hello world"
That's it, folks, enjoy your weekend!
History
String#capitalize has been part of Ruby since version 1.0 released in 1996.
It appears that some Smalltalk dialects had a capitalize method on String as well, which may have been the original source of inspiration. Python had the module function string.capitalize(variable) in its standard library in the 90s, but it's unclear to me if it predates Ruby's method or not.