Online Ruby Compiler

Run Ruby 3.4 with the standard library, gets and STDIN. It is CRuby compiled to WebAssembly, so your code never leaves the page.

Runs in your browser · Nothing uploadedFree · No sign-upRuby 3.4

Start from an example

main.rb

Standard input (stdin)

Output

Nothing has run yet

Press Run to see what the program prints, or load one of these:

Embed this compiler

Paste this into your page. Visitors run code in their own browser, and nothing is sent to us.

CRuby 3.4, running in this tab

This is ruby.wasm, the official build of CRuby 3.4 for WebAssembly, with the standard library bundled in. puts, p, gets and STDIN.read work against the boxes on this page, and error messages read the way ruby prints them in a terminal.

The catch is size. The first run downloads about 29 MB (around 9 MB compressed). After that the interpreter stays loaded, and later runs start in about a tenth of a second.

At a glance
Version
Ruby 3.4.1
Platform
wasm32-wasi
Input
gets, STDIN.read
Gems
None
Run limit
10 seconds
First load
About 29 MB, then cached

What works and what does not

We ran every row of this table in the compiler before writing it down.

FeatureWorks?
puts, print, p, pp

Output is written as it happens, so you still see it if the run is stopped.

Yes
gets, STDIN.read, $stdin

All three read the stdin box. gets returns nil once it runs out.

Yes
Standard library

json, set, date, time, prime, matrix, csv, yaml, digest, securerandom, stringio, benchmark and more.

Yes
Fibers and Enumerators

Generators built on Fiber.yield or an Enumerator run normally.

Yes
sleep

It really waits, so it counts toward the 10-second limit.

Yes
File.write and File.read

They work during a run. Each run starts with an empty file system.

Partly
Thread.new

Raises NotImplementedError. This build has no threads.

No
bigdecimal

Not included in this WebAssembly build.

No
Gems (Nokogiri, Rails, RSpec)

Nothing can be installed, so require raises LoadError.

No
Net::HTTP and sockets

The socket library is missing, and the sandbox blocks the network.

No

Why run Ruby here

A new VM for every run

Constants, globals and monkey patches from the last run are gone. Only the compiled interpreter is kept, which is why runs stay quick.

Error messages you recognize

Backtraces are trimmed to main.rb lines, and syntax errors show the Ruby 3.4 caret diagram pointing at the problem.

Fibers work

Threads are not available, but Fiber-based generators and lazy Enumerators run fine.

Stop works mid-loop

loop { } does not hang the page. Press Stop or wait 10 seconds, and the interpreter is shut down and restarted.

Errors you will probably hit

The first one trips up almost everyone who reads input.

undefined method 'chomp' for nil (NoMethodError)

What it meansgets returned nil because the stdin box ran out of lines.

FixAdd the missing input, or write gets.to_s.chomp so the end of input becomes an empty string.

cannot load such file -- nokogiri (LoadError)

What it meansGems are not installed here.

FixStick to the standard library, or run the script locally with bundle exec.

initialize() function is unimplemented on this machine (NotImplementedError)

What it meansThread.new was called, and this build has no threads.

FixDo the work in order, or use a Fiber.

stack level too deep (SystemStackError)

What it meansThe recursion went deeper than the WebAssembly stack allows.

FixRewrite it as a loop, or cache results in a Hash so fewer calls are needed.

syntax errors found (SyntaxError)

What it meansRuby could not parse the file. The caret lines under the message show where.

FixFix the marked spot. A missing end or a dangling operator is the usual cause.

How this Online Ruby Compiler works

When you press Run, the page passes your code and stdin to a sandboxed frame that cannot see this site, your cookies or the network. Inside it, a Web Worker runs ruby.wasm, which is CRuby 3.4 compiled to WebAssembly.

The first run downloads about 29 MB, which your browser caches. The compiled interpreter is kept between runs, but each run gets a brand-new VM and an empty file system, so nothing carries over.

How to use this Online Ruby Compiler

1

Write your code

Start from the sample, pick an example above the editor, or paste your own script.

2

Add stdin

One value per line. Each gets call takes the next line.

3

Run it

Press Run Ruby or Ctrl+Enter. The first run downloads the interpreter, then the output appears on the right.

Example Usage

With 3 4 5 in stdin, this adds up the numbers on the first line.

Input
puts gets.split.map(&:to_i).sum
Output
12

Frequently Asked Questions

Which Ruby version is this?
Ruby 3.4.1, built for wasm32-wasi by the ruby.wasm project. It is CRuby, the same interpreter you install with rbenv or asdf, compiled to WebAssembly.
Why is gets returning nil?
The stdin box has no more lines. The whole box is handed to your program at the start, and it cannot ask you for more while it runs. Add a line per gets call, or use gets.to_s.chomp.
Can I install gems?
No. Only the standard library is available, and the sandbox has no network access to fetch gems. json, set, date, csv, yaml and prime are included.
Why is the first run slow?
Your browser downloads the Ruby interpreter, about 29 MB (around 9 MB compressed), and caches it. Later runs on the same page start in about a tenth of a second.
Is my Ruby code sent to a server?
No. It runs in your browser, inside a sandboxed frame and a Web Worker that cannot reach the network. Share links store the code after the # in the URL, and browsers never send that part to a server.
Can I use threads?
No. Thread.new raises NotImplementedError in this build. Fibers and Enumerators work, which covers generator-style code.

Related Tools

Comments

Comments are provided by Disqus, which sets cookies and processes data under its own privacy policy.

The Online Ruby Compiler is maintained by CodeItBro. We aim to provide the best free developer tools on the web. If you have feedback or suggestions, please visit our contact page.

As featured on

CodeItBro - Free dev tools + practical guides to help you ship faster | Product HuntCodeItBro - Free Online Developer Tools badgeCodeItBro badgeFeatured on neeed.directory