Ad space (banner)
๐Ÿ’ŽRuby Lessons
Lesson 13 / 68

Using the Standard Library

In this lesson you will learn the handy string methods in Ruby's standard library so you can work faster. This is for anyone searching for "Ruby string methods list".

Ruby has a great many convenient methods for working with text. .upcase, .rjust, and .length are among the most used. Ruby's standard library is remarkably expressive, and simply knowing it makes your code look considerably more polished.

The sample code converts to upper case with "hello".upcase, pads with zeros using "7".rjust(3, "0"), and reads the number of elements with [1, 2, 3].length. Notice how a single short method call achieves each practical result.

A common stumbling block for beginners is not realising a method for the job already exists and writing it from scratch. Getting into the habit of checking the official Ruby reference for something similar improves both the quality and the speed of your code.

Having a working knowledge of the string and collection methods makes you noticeably faster. The richness of Ruby's standard library is a big part of what makes the language so productive.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run Ruby directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)