Skip to content

Ruby practice

Practice Ruby online: 10 exercises, graded problems and a playground

The interpreter behind these exercises is CRuby itself — the official Ruby, compiled to WebAssembly by the ruby.wasm project — so puts, string interpolation, blocks and each behave exactly as they do in irb. The exercises take you from your first puts to a small complete program, and the playground is where you try the idiom you just learned on something of your own.

checked exercises
10
graded problems
0
lessons
0
cheat sheet (coming)
0

Ruby practice exercises

How the path works →

In order, each one introducing a single new idea. Press Run to check your answer; hints open one at a time.

  1. Hello, Out Loudputs prints text followed by one newline
  2. Name TagA variable stores a value, and #{...} drops it into a string
  3. Party PlannerInteger division truncates with /, and % gives the remainder
  4. Umbrella or Notif / elsif / else chooses between several outcomes
  5. Countdowndownto repeats a block once for every number in a falling range
  6. The Clapping Gamean if inside a loop is decided again on every pass
  7. The Scoreboardljust and rjust pad a string to a fixed width so columns line up
  8. Packing ListAn array holds several values in order, and each walks through them
  9. Rainfall Weeka variable created before a loop carries a running total from pass to pass
  10. The Bike Rental ReceiptAssembling a complete program out of parts you already know

Coding interview questions

Original questions with full model answers, for when the practice is going somewhere specific.

Questions people ask

Is this real Ruby?
Yes: CRuby 3.4, the standard interpreter, running inside your browser tab. Gems that need a network or a filesystem are not available; the core language and standard library are.
Does gets work for reading input?
It does. Type lines into the input box beside the editor and gets returns them one at a time, trailing newline included — which is exactly why the exercises show you .chomp early.
Why does the first Run pause for a moment?
Ruby is downloaded once, about 29 MB, and started inside the browser. Every Run after that is immediate until you close the tab.
What is on this page besides the exercises?
The 10 exercises come first; then a blank playground.

Practise another language

The same kind of practice hub exists for Python, JavaScript, TypeScript, Java, C++, C, C#, Go, PHP, SQL, R and Bash & the Shell.