Ruby’s puts, print and inspect produce different views of the same value. Ruby Playground shows those differences in the output of small programs, including the array and class examples below.

Read the default result

The initial snippet maps [1, 2, 3, 4] to [2, 4, 6, 8] and prints its sum, 20. inspect makes the array readable; puts writes a newline. print does not add a newline, but its final fragment still appears in the output.

Find prime numbers

Choose Find prime numbers, confirm replacement if asked, then press Run. It prints:

[2, 3, 5, 7, 11, 13, 17, 19, 23, 29]

The predicate rejects integers below 2, then tests divisors up to Integer.sqrt(n). Any larger factor would have a matching smaller factor. Ruby’s (2..30) includes both endpoints; change it to (2..50) to extend the exercise.

Classes and patterns

Choose OOP: bank account to see a class whose deposit and withdraw methods update @balance. Depositing 100 and withdrawing 30 prints Balance: 70. attr_reader exposes the balance without adding a setter.

Centered pyramid prints:

    *
   ***
  *****
 *******
*********

String multiplication repeats the spaces and stars. Row r uses height - r spaces and 2 * r - 1 stars. Copy output preserves the indentation. Other examples include sorting, binary search, word counts, odd/even numbers and hollow or inverted pyramids.

Interactive input and error recovery

Choose Read standard input and Run in Interactive terminal mode. Enter Ilham in the console when this snippet waits for input:

name = STDIN.readline.chomp
puts "Hello, #{name}!"

It prints Hello, Ilham!. Provide another answer for each additional read. EOF ends input and can raise EOFError; Run again to supply the missing answer. Alternatively, select Prepared standard input and fill one answer per line before Run. Your code remains in the editor. Syntax errors and raised exceptions also appear in the output. Stop terminates a stuck loop.

Interactive stdin requires HTTPS and service workers. Its first Run registers a service worker scoped to /tools/, handling only reserved input requests locally without caching pages or persisting answers. If unavailable, use prepared input. This is line-based input, not a shell.

Runtime assets are fetched from jsDelivr; an unavailable CDN prevents execution, not editing. Each Run uses a fresh virtual filesystem and loses earlier variables. The plain editor works without Monaco, and no Ruby formatter is bundled.

References

Questions you might have

How do I read input?
Use STDIN.readline.chomp in Interactive terminal mode, then answer in the console with Enter. EOF (or Ctrl + D) ends the stream; readline can raise EOFError. Prepared standard input remains available for answers supplied before Run.
Why does the first Run take longer?
The Ruby WASM binary is approximately 16 MiB before compression. It downloads from jsDelivr and initializes in a fresh Worker. Runtime loading has a 90-second timeout, followed by a 30-second execution limit outside input waits. Each answer can wait up to 2 minutes. Normal HTTP caching can reuse assets between runs.
Can I install gems or run Rails?
This runner provides a browser WASI build, not a desktop Ruby installation or a web server. No gems are installed automatically; arbitrary native extensions and OS subprocesses are unavailable.
Does selecting an example erase my code?
Yes. Selecting immediately replaces code and standard input, and pauses Auto-run. If the editor contains more than one line, confirm deletion of existing code or cancel to keep code and input.
Is this a security sandbox?
No. A Worker prevents direct DOM access and can be terminated, but Ruby’s JavaScript bridge can make network requests. The tool itself does not upload or persist code or input. Each Run starts fresh; output is limited to 500 rows.