← Ruby Playground

PhRUG · 25-minute talk · Opening: 2 minutes

Ruby Playground: Learn Ruby by Working with Code

Nestor Pestelos ·

Show the QR code

You learn Ruby fastest when each step builds on the last and you find out right away whether you got it right.

Learn in order and check yourself often.

You can follow these examples without knowing Ruby. Read from top to bottom. p(...) displays the value inside the parentheses. Make a prediction before each run.

The first Run downloads Ruby into your browser through WebAssembly. JavaScript and a network connection are needed to run examples. Each run starts fresh. Reset restores the starting code; Stop ends a running example. The code and answers remain readable without JavaScript.

1. Predict division

5 minutes

Predict first: What does p(7 / 2) print?

Show expected output
3

Most people guess 3.5. Ruby gives 3. Both inputs are integers, or whole numbers. 7.0 is a float, a number written here with a decimal point.

Change: replace the code with p(7.0 / 2).

Show expected output after the change
3.5

Ruby syntax: / between two integers is integer division and rounds down. A float such as 7.0 makes the same / produce a float.

Which part of your first prediction needs to change? Try the full Values lesson for more practice.

2. Predict what + does with text

4 minutes

Predict first: What does p("2" + "3") print?

Quotes make "2" a string, which holds text.

Show expected output
"23"

The result is "23". The quoted numbers are text.

Change: replace "3" with "Ruby", so the line is p("2" + "Ruby").

Show expected output after the change
"2Ruby"

Ruby syntax: For strings, + joins text. p keeps the quotes visible so you can see the result is a string.

What is implicit conversion? (opens in a new tab or window)

3. Predict what the counters remember

9 minutes

Predict first: What four numbers do these calls print, and do first and second share a count?

This example comes from Blocks, then closures. It jumps ahead to show where the foundations lead. The lesson sequence gives you the steps in between.

def ... end defines a method, a named piece of code. count = 0 starts a counter. -> { count += 1 } creates a lambda: code we can call later to increase that counter by one.

Each make_counter call returns a lambda. first and second name the two results. .call runs a lambda, and puts displays its result on a new line.

Show expected output
1
2
1
3

Each call to make_counter creates its own count and returns a lambda. After the method returns, each lambda reads and increases its own count.

Change: add one more puts first.call at the end. Predict the fifth number before running again.

Show expected output after the change
1
2
1
3
4

Ruby syntax: A lambda (-> { ... }) can keep using a local variable from the method that created it. That is a closure.

What is a lambda? (opens in a new tab or window)

The full Blocks, then closures lesson builds from blocks to closures. Start with Values if these pieces are new.

Keep learning in order

Closing and feedback: 5 minutes

Each lesson builds on the last. The Ruby skill tree shows prerequisites so you can choose the next step from what you already know. Planned lessons are marked separately.

The site has 16 live lessons:

The approach is influenced by Justin Skycak's Advice on Upskilling, especially active practice and strong foundations.

Which topic needs a clearer explanation? What would make these lessons useful in your learning or teaching?

Follow along on your phone

QR code for the PhRUG talk page at rubyplayground.org/talks/phrug/20261126/
Scan to follow along, or open https://rubyplayground.org/talks/phrug/20261126/.

Abstract

I'm building Ruby Playground as my contribution to the Ruby community. I want it to help people new to Ruby learn the language and give experienced Rubyists a place to keep learning as Ruby develops.

In this talk, I'll demonstrate editable examples from Values and Blocks, then closures. Ruby Playground now has 16 live lessons, linked above and mapped in the skill tree. Examples run Ruby in the browser through WebAssembly, without a local Ruby installation. Running them needs JavaScript and a network connection; the code and answers remain readable without JavaScript.

The learning approach is influenced by Justin Skycak's Advice on Upskilling, especially active practice and strong foundations. Learners predict an example's output, run it, and change the code to check their understanding.

The project starts with Ruby's fundamentals, with future lessons planned about changes in specific Ruby versions. I'd like feedback from PhRUG on which topics need clearer explanations and what would make these lessons useful in your learning or teaching.