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

Instructions

1.

Call the .length method on your name (remember to use quotes around your name).

puts the answer to the console if you want to see the value.

Folder Icon

Take this course for free

Already have an account?