XCODX |

Ruby Online Compiler & Interpreter

Select Language
Online Code Compiler
Full HTML IDE
Py main.py
Program Output Ready
  Welcome to XCODX Online Compiler

  Quick Start:
  Ctrl+Enter  Run code
  Ctrl+S      Save / Download
  Ctrl+L      Clear output

  Select a language and start coding.
Success
Operation completed

About Ruby

Ruby was created by Yukihiro "Matz" Matsumoto in Japan and released publicly on December 21, 1995, designed around a single guiding idea: optimize for programmer happiness and let code read almost like English. It is thoroughly object-oriented, so even integers and nil are objects with methods, and it leans on blocks, iterators, and expressive method names to keep programs short and legible. On XCODX, Ruby runs on MRI, the reference interpreter also known as CRuby, which is the same engine behind most Ruby installations. You get the core language plus its standard library, so puts, gets, Array, Hash, and modules such as json and set are all available, but this is plain Ruby rather than Rails. Because there is no gem install and no Bundler, third-party gems and web frameworks are out of scope; what you write here is scripts, not servers. That makes it a quick place to practice blocks, string methods, or an algorithm without installing rbenv or a full local toolchain.

Hello World in Ruby

# A short tour of Ruby basics

def greet(name)
  "Hello, #{name}!"
end

puts greet("XCODX")

languages = ["Ruby", "Python", "PHP"]
languages.each_with_index do |lang, i|
  puts "#{i + 1}. #{lang}"
end

squares = (1..5).map { |n| n * n }
puts "Squares: #{squares.join(", ")}"
puts "Sum: #{[10, 20, 30].sum}"

When to use Ruby

Ruby shines at readable, expressive scripting and at web development through Ruby on Rails, whose convention-over-configuration approach still powers products like Shopify, GitHub, and Basecamp. Choose it when developer productivity and clean, maintainable code matter more than raw execution speed: a SaaS backend, a command-line tool, a text-processing script, or a prototype you want standing up quickly. Its flexibility and many ways to express the same thing can drift into inconsistent style across a large team unless a style guide is enforced. For CPU-bound number crunching, low-latency systems work, or heavy concurrency it is not the strongest choice, where Go or a JVM language tends to fit better.

Common questions

Can I use gems like Rails or Nokogiri on this compiler?

No. The sandbox has no gem install and no Bundler, so third-party gems such as Rails, Sinatra, Nokogiri, and RSpec are unavailable. You can require what ships with MRI's standard library, for example json, set, date, and securerandom, but nothing pulled from RubyGems.org.

How do I read user input in Ruby here?

Use gets to read a line from standard input and call .chomp to strip the trailing newline, as in name = gets.chomp. The interactive terminal streams your keystrokes and pauses at gets until you press Enter; STDIN.gets does the same thing explicitly, and Ctrl+D closes the stream.

Can I build a Rails app or run a web server?

Not in this sandbox. Rails is a third-party gem, and there is no gem installation, no network access, and no persistent filesystem, so nothing can listen for or accept requests. It runs plain Ruby scripts top to bottom and prints to the terminal, which is ideal for learning the language that Rails is built on.

Why does gets return a string when I type a number?

gets always returns a String, so typing 42 gives you the text "42\n", not an integer. Convert it with .to_i or .to_f, as in age = gets.to_i, otherwise arithmetic will fail or your values will be concatenated as text instead of added.

What is the difference between puts, print, and p?

puts writes its argument and adds a newline, print writes it without one, and p prints a developer-friendly inspected form, so a string shows its surrounding quotes. Use p when debugging because it reveals the exact object, and puts for clean user-facing output.

Which Ruby version runs, and are there limits?

The exact MRI version appears in the badge and it is a current Ruby 3 series release, so pattern matching, endless methods, and the modern standard library all work. Runs are capped by a short timeout and roughly a 50 KB code limit, and each run starts on a fresh filesystem, so anything written to disk does not persist.

How Ruby runs on XCODX

Sandbox filename
main.rb
Entry point
single main source file
Editor grammar
ruby
Reading stdin
gets
Input delivery
live WebSocket stream
Prompt flushing
unbuffered automatically ($stdout.sync = true is prepended on live runs)
Compile limit
10 s
Run limit
3 s batch · up to 3 min live
Memory
256 MB per stage
Max source
50,000 characters

Default program on this page

puts "Hello from Ruby!"
puts "Welcome to XCODX Online Compiler!"
languages = ["Ruby", "Python", "JavaScript"]
puts "Languages: #{languages.join(', ')}"