Ruby · Course navigation

Ruby Basics

Store text and print it.

On this page

The concept

Assignment binds a value to a name. String interpolation inserts an expression inside double-quoted text. puts writes a line.

Code example

Ruby
name = "Ada"
puts "Hello, #{name}"
Output
Hello, Ada

Follow the code

Open the walkthrough to inspect the example one step at a time.

Show guided walkthrough
Guided walkthroughReady
1name = "Ada"
2puts "Hello, #{name}"

Follow the example

Start to inspect the source, values, and output. These prepared steps explain the published sample; grouped loop steps describe multiple iterations.

View the complete dry-run table
Prepared trace of the published program. Some rows group repeated iterations.
Step / lineWhat happensState after stepOutput so far
Assign the string to name.name = "Ada"
—
Interpolate name and write a line.name = "Ada"
Hello, Ada

Behind the scenes

How Ruby processes this code

Ruby parses and executes the script. Blocks run when their methods invoke them.