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.
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.
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.
# 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}"
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.
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.
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.
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.
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.
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.
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.
main.rbrubygetsputs "Hello from Ruby!"
puts "Welcome to XCODX Online Compiler!"
languages = ["Ruby", "Python", "JavaScript"]
puts "Languages: #{languages.join(', ')}"