Lightweight Ruby IDE - Run Ruby Code Online

Write, run, and debug Ruby in a lightweight online IDE with multi-file editing, persistent workspaces, runtime libraries, sharing, and live collaboration.

🚀 232,973 total executions (100 this month)

Udemy Logo Udemy Affiliates: The best Ruby courses you should try

Loading…

💡 Looking to improve your skills? These courses may help—check them out while our AI model processes your request.

💎 About This Ruby Online Executor

The CodeUtility Ruby Executor allows you to write, run, and test Ruby code instantly in your browser - no installation or setup needed. It runs in secure, isolated environments powered by real Ruby interpreters, supporting versions 2.7, 3.1, and 3.2.

Whether you're practicing Ruby fundamentals, testing algorithms, or learning object-oriented programming, this tool provides a simple and interactive console for immediate feedback.

You can use it to explore Ruby syntax, play with gems, or debug short snippets without configuring a local environment. It’s ideal for learners, backend developers, and anyone experimenting with Ruby-based logic.

All executions are processed in sandboxed environments to ensure safety and reliability while preserving real Ruby behavior.

More than a code runner

Use a multi-file editor, an isolated execution terminal, runtime-specific libraries, persistent workspaces, sharing, and real-time collaboration from the same executor.

How to use this executor?

Choose a runtime, open or create a file, write your code, and select Run. Output appears in the terminal, while signed-in users can keep files in a workspace, install libraries, and collaborate through shares.

  1. Select a version and edit the current file or open another workspace file.
  2. Run the code, provide input in the terminal when requested, and review saved run history.
  3. Use libraries, workspace tools, sharing, and chat when your task needs more than one snippet.

💡 Ruby Basics Guide for Beginners

1. Declaring Variables and Constants

Ruby is dynamically typed. Constants start with uppercase letters and are not meant to change.

x = 10
pi = 3.14
name = "Alice"
is_active = true

MAX_USERS = 100
APP_NAME = "CodeUtility"

2. Conditionals (if / case)

Use if, elsif, else, or case for control flow.

x = 2
if x == 1
  puts "One"
elsif x == 2
  puts "Two"
else
  puts "Other"
end

case x
when 1
  puts "One"
when 2
  puts "Two"
else
  puts "Other"
end

3. Loops

Use while, until, or iterators like each.

i = 0
while i < 3
  puts i
  i += 1
end

[1, 2, 3].each do |n|
  puts n
end

4. Arrays

Arrays store ordered lists of elements. Access using indexes.

fruits = ["apple", "banana", "cherry"]
puts fruits[0]
puts fruits.length

5. Array Manipulation

Use push, pop, slice, and reverse for working with arrays.

fruits.push("kiwi")
fruits.pop
puts fruits[1..2]
puts fruits.reverse

# Array comprehension
squares = (1..5).map { |x| x * x }
puts squares

6. Console Input/Output

Use gets.chomp to read input and puts/print for output.

print "Enter your name: "
name = gets.chomp
puts "Hello, #{name}"

7. Functions

Define functions using def. You can pass arguments and return values.

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

puts greet("Alice")

8. Hashes

Hashes are key-value pairs, like dictionaries or maps.

person = { "name" => "Bob", "age" => 25 }
puts person["name"]

# Symbol keys
person = { name: "Alice", age: 30 }
puts person[:name]

9. Exception Handling

Use begin-rescue-end to catch exceptions and handle errors gracefully.

begin
  raise "Something went wrong"
rescue => e
  puts e.message
end

10. File I/O

Read and write files using File methods or IO classes.

File.write("file.txt", "Hello File")
content = File.read("file.txt")
puts content

11. String Manipulation

Ruby strings support many methods: length, gsub, split, etc.

text = " Hello World "
puts text.strip
puts text.upcase
puts text.gsub("Hello", "Hi")
puts text.split

12. Classes & Objects

Ruby is fully object-oriented. Use initialize to define constructors.

class Person
  def initialize(name)
    @name = name
  end

  def greet
    "Hi, I'm #{@name}"
  end
end

p = Person.new("Alice")
puts p.greet

13. References (Object Mutation)

All variables hold references to objects. Modifying an object inside a function affects the original.

def modify(arr)
  arr << "changed"
end

data = ["original"]
modify(data)
puts data.inspect  # ["original", "changed"]