Introduction to Ruby

The '.length' Method

Methods are summoned using a .. If you have a string, "I love espresso", and take the .length of it, Ruby will return the length of the string (that is, the number of characters—letters, numbers, spaces, and symbols). Check it out:

"I love espresso".length
# ==> 15

(That little line starting with the # isn't part of what you need to write—it just shows you the output Ruby will provide. More on this in the next section!)

Taking the length of input can be useful if, for example, you want to make a website that takes credit card payments. Ruby can check to make sure the credit card number appears to be valid.

Community Forums
Get help and ask questions in the Codecademy Forums
Report a Bug
If you see a bug or any other issue with this page, please report it here.