Skip to content
Online Compiler

Online Ruby Compiler

Write Ruby and run it right here. Ruby runs inside your browser, so nothing you type is uploaded. The first run downloads the runtime.

Ready

# gets reads one line from the input box.
name = gets&.chomp || "world"
puts "Hello, #{name}!"

(1..3).each do |i|
  puts "#{i} squared is #{i * i}"
end

Type the input before you run. Each gets call reads the next line.

Output

Press Run or Ctrl+Enter to see the output here.

Runs in your browser with Ruby 3.4 (ruby.wasm 2.10.1). Your code is not sent to a server.

How to run Ruby code here

  1. Write or paste your Ruby code into the editor. There is a short example in it to start from.
  2. If your program reads input, type it into the input box first — one value per line.
  3. Press Run or Ctrl+Enter. The output appears next to the editor, with errors shown in red.

How this page runs Ruby

Runtime: Ruby 3.4 (ruby.wasm 2.10.1)

Ruby runs as CRuby 3.4 compiled to WebAssembly by the ruby.wasm project (version 2.10.1), together with its standard library, so require "set", "json" or "date" works. The first run downloads about 8 MB from the jsDelivr CDN, and later visits load it from the browser cache. Every run starts a fresh Ruby VM, so classes and constants from the last run are gone. Exceptions are printed with their message, class and a backtrace pointing at main.rb.

Everything happens on your device. The code you write is never uploaded, logged or stored on a server. Each run stops after 10 seconds and keeps up to 100,000 characters of output, so an endless loop cannot freeze the page.

What is not available

Gems cannot be installed, and this WebAssembly build of Ruby has no Thread, so code that starts threads or uses Timeout fails. There is no access to the network or to files on your computer. Programs that read input in a loop get nil once the input box has been read to the end.

Ruby examples

Open an example in the editor above, change it and run it. Opening an example does not run it.

FizzBuzz with a range

(1..15).each do |i|
  word = ""
  word += "Fizz" if (i % 3).zero?
  word += "Buzz" if (i % 5).zero?
  puts word.empty? ? i : word
end

Arrays and hashes with blocks

numbers = [5, 3, 8, 1, 9, 2]

p numbers.select(&:even?)
p numbers.map { |n| n * n }
p numbers.sort.reverse
p numbers.each_slice(2).to_a
puts numbers.sum, numbers.minmax.inspect

ages = { "Ada" => 36, "Linus" => 21, "Grace" => 45 }
ages.sort_by { |_, age| age }.each { |name, age| puts "#{name}: #{age}" }

A class that includes Comparable

class Temperature
  include Comparable
  attr_reader :celsius

  def initialize(celsius)
    @celsius = celsius
  end

  def fahrenheit = celsius * 9.0 / 5 + 32
  def <=>(other) = celsius <=> other.celsius
  def to_s = format("%.1f°C / %.1f°F", celsius, fahrenheit)
end

temps = [30, -5, 18].map { Temperature.new(_1) }
puts temps.max
puts temps.sort.map(&:to_s)

Counting words with tally

text = $stdin.read.downcase
counts = text.scan(/[a-z']+/).tally
counts.sort_by { |word, n| [-n, word] }.first(3).each do |word, n|
  puts "#{word}: #{n}"
end

Input

the cat and the dog.
The end!

Custom exceptions and rescue

class NegativeError < StandardError; end

def parse_age(text)
  age = Integer(text)
  raise NegativeError, "age cannot be negative" if age.negative?
  age
end

%w[42 -1 abc].each do |raw|
  puts "#{raw} -> #{parse_age(raw)}"
rescue NegativeError, ArgumentError => e
  puts "#{raw} -> error: #{e.message}"
end

Reading input in Ruby

Programs here do not stop and wait for you to type while they run. Everything your program reads comes from the input box, which you fill in before pressing Run.

gets reads the next line including its newline, so write gets.chomp — or gets&.chomp when the input might be empty. $stdin.read returns everything at once and $stdin.each_line goes through it line by line. At the end of the input, gets returns nil.

Saving and sharing

Your latest Ruby code and input are saved automatically in this browser, so they are still here when you come back. Nothing is saved on a server.

Share creates a link that carries your code inside the address itself, compressed after the # sign. Whoever opens it sees your code in the editor, and it only runs when they press Run.

Keyboard shortcuts

KeysAction
Ctrl+EnterRun the code
Ctrl+/Comment or uncomment the line
Tab · Shift+TabIndent or outdent the selection
Ctrl+FFind and replace in the code
Ctrl+Z · Ctrl+Shift+ZUndo / redo
Esc → TabLeave the editor with the keyboard

On a Mac, use ⌘ instead of Ctrl.

Frequently asked questions

Which Ruby version does this use?

Ruby 3.4 — the interpreter is CRuby, the standard implementation, built for WebAssembly by ruby.wasm 2.10.1. Newer syntax such as endless methods, pattern matching and numbered block parameters all works.

Can I use gems or Rails?

No. Only the standard library that ships with Ruby is available, and there is no way to install gems. Rails and other frameworks also need a server, which this site deliberately does not have.

Why do Thread and Timeout not work?

WebAssembly in the browser gives this Ruby build no operating-system threads, so Thread.new raises NotImplementedError and libraries that depend on threads, such as Timeout, fail the same way. Fibers and ordinary blocks work.

Is this Ruby compiler free?

Yes. There is no account, no sign-up and no daily limit. The only limit is that a single run stops after 10 seconds.

Is my Ruby code sent to a server?

No. The Ruby runtime is downloaded into your browser and your code runs there, on your device. The site only serves the page and the runtime files; it never receives the code you write or the input you give it.

Where is my code saved?

In this browser's local storage, one draft per language. It stays until you clear this site's data, and it is not synced to other devices. Use a share link to move code somewhere else.

How do I share my Ruby code?

Press Share and send the copied link. The code is compressed into the part of the link after #, which browsers never send to a server. Very long programs do not fit in a link, and the page will tell you when that happens.

Does it work on a phone or tablet?

Yes. It runs in any current mobile browser. On a slow connection the first run takes longer because the runtime has to be downloaded once.

Run another language