Using Strings in Ruby
In this lesson, we are going to walk through how to use Strings in a Ruby program.
Guide Tasks
  • Read Tutorial
  • Watch Guide Video
Video locked
This video is viewable to users with a Bottega Bootcamp license

In this lesson, we are going to walk through how to use Strings in a Ruby program.

A string is a data type in Ruby and contains set of characters, typically normal English text (or whatever natural language you're building your program for), that you would write. A key point for the syntax of strings is that they have to be enclosed in single or double quotes if you want to use them in a program. The program will throw an error if they are not wrapped inside quotation marks.

Let's walk through three scenarios.

Missing Quotation Marks

large

In this code I tried to simply declare a string without wrapping it in quotation marks. As you can see this results in an error. This error is because Ruby thinks that the values are classes and methods.

Printing Strings

large

In this code snippet we're printing out a string that we have properly wrapped in quotation marks. Please note that put single and double quotation marks work properly.

Storing Strings in Variables

large

Lastly in this code snippet we're storing a string inside of a variable and then printing the value out to the console.


We'll talk more about strings and string interpolation in subsequent lessons.