Ruby PlaygroundRuby Tutorial
UI ThemeDark

Lesson 1 of 23 · Ruby 3.3

Run Ruby and inspect values

Run a short Ruby program and choose how to display its values.

Learn

A Ruby program evaluates code in order. A value can be a number such as 12 or text inside quotes such as "Welcome". An expression produces a value: 12 + 3 adds two numbers. Press Run to execute the code in the editor.

puts displays a value as text on its own line. p displays an inspection form that is useful when exploring values; for a string, it includes surrounding quotes. Both are methods supplied by Ruby. These examples call them by writing the method name followed by the value to display.

Write each instruction on a new line. Blank lines can separate related instructions. A # outside a quoted string starts a comment that Ruby ignores through the end of that line.

Example

puts "Welcome"
puts 12 + 3
p "Welcome"

Experiment

  • Run this short sign message. Replace only the second puts with p, then compare how the same text is displayed.

  • Predict which lines display something, then run. Add puts before the calculation so that you can inspect its value too.

Explore the official manual

Ruby 3.3.3 · Example

Ready to run

Output

Run the code to see what happens.