Open the Ruby Playground for small Ruby experiments without a backend.

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

Clear the editor and choose Find prime numbers. 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.

Prepare input and recover from errors

The Read standard input example fills an empty input field with Ilham:

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

It prints Hello, Ilham!. Provide another line for each additional read. If an EOFError appears, add the missing answer and Run again; your code remains in the editor. Syntax errors and raised exceptions also appear in the output. Stop terminates a stuck loop.

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?
Fill Standard input before Run, one answer per line, then use STDIN.readline.chomp. Missing answers raise EOFError. This is prepared input, not a live terminal.
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 separate 30-second execution limit. 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?
No. It adds code above the existing snippet and pauses Auto-run. Clear first to run just the example. Ruby examples share the snippet’s namespace, so later definitions can replace earlier ones.
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.