Ruby Compiler
Run Ruby 4.0 code online with the standard library and stdin input. CRuby runs in your browser as WebAssembly, so your code never leaves your device.
Something not working, or missing a feature? Send feedback
About the Ruby Compiler
The online Ruby Compiler runs your code with CRuby 4.0, the reference Ruby implementation, compiled to WebAssembly with the standard library included. Test a method, try a new syntax feature or check a Struct, Set or JSON snippet without installing Ruby; the interpreter runs in your browser, so your code stays on your device.
Your code runs in an isolated Web Worker in your browser, so it never leaves your device.
How to use the Ruby Compiler
- Write or paste Ruby code.
- Put the lines your program reads with gets or STDIN.read in the stdin box.
- Click Run. The first run downloads Ruby (about 9 MB); later runs start in under a second.
- Read the output, or the error with its line number in main.rb.
Example
Input
counts = STDIN.read.downcase.scan(/\w+/).tally
counts.sort_by { |word, n| [-n, word] }.first(3).each do |word, n|
puts "#{word}: #{n}"
endResult
the: 3 cat: 1 dog: 1
With "the cat saw the dog" and "the end" in the stdin box. tally counts each word, and sorting by [-n, word] puts ties in alphabetical order.
Common mistakes
- gets returns nil at the end of input. Once the stdin box is used up, gets returns nil, so gets.chomp raises NoMethodError. Use gets&.chomp, or loop with while (line = gets).
- puts, print and p. puts adds a newline and prints arrays one element per line; print adds nothing; p shows the inspected value, with quotes around strings. Use p when you need to see exactly what a value is.
- Requiring a gem. Only the standard library is installed, so require "nokogiri" or "rails" fails with LoadError. Try the logic with standard classes such as Set, Struct, Data and JSON.
Works well with the Ruby Compiler
- Regex Tester: build and test the regular expressions your script uses.
- Python Compiler: compare the same script in Python.
- JSON Formatter: inspect the JSON your program prints.
Frequently asked questions
Which Ruby version is it?
CRuby 4.0 (the RUBY_VERSION constant prints 4.0.0), so pattern matching, endless methods, Data, the it block parameter and the Prism parser are all available.
Can I use gems?
The standard library is included, so require "json", "set", "date", "time" and "securerandom" work. Gems from rubygems.org cannot be installed in the sandbox.
Is my code sent to a server?
No. The Ruby interpreter runs in your browser as WebAssembly, so the code and its input stay on your device.
Is it a compiler or an interpreter?
An interpreter, like the ruby command: CRuby compiles your code to bytecode and runs it immediately. "Ruby compiler" is simply what most people search for.
Related tools
JavaScript Compiler
Run JavaScript online in an isolated browser sandbox. See console output, errors and execution time instantly, with top-level await and stdin input.
TypeScript Compiler
Compile and run TypeScript online. Your code is type-checked with the official compiler in strict mode, then runs in a sandboxed worker in your browser.
Python Compiler
Run Python 3 code online with the full standard library and stdin input. It runs in your browser with Pyodide (WebAssembly), so your code stays on your device.
PHP Compiler
Run PHP 8.4 code online and see the output instantly, with stdin input and mbstring. PHP runs in your browser with WebAssembly, so your code stays private.
C Compiler
Compile and run C code online with Clang 21, a GCC-compatible compiler, and stdin input. Programs run in your browser as WebAssembly, so your code stays private.
C++ Compiler
Compile and run C++20 code online with Clang 21, libc++ and stdin input. Programs compile to WebAssembly and run in your browser, so your code stays private.