Ruby
v3.0.1
Ruby
v3.0.1
Ruby is a dynamic, open-source programming language with a focus on simplicity and developer productivity. It was created by Yukihiro "Matz" Matsumoto in Japan and first released publicly in 1995. Ruby is purely object-oriented (everything is an object), supports functional and imperative styles, and is known for its elegant, readable syntax and powerful metaprogramming.
Ruby is widely used for web development, most famously through the Ruby on Rails framework, as well as for scripting, automation, DevOps tooling, and prototyping. Its rich standard library and the RubyGems ecosystem make it a productive choice for building APIs, command-line tools, and full-stack web applications.
puts "Hello, World!"print "Enter your name: "
name = gets.chomp
puts "Hello, #{name}!"fruits = ["apple", "banana", "cherry"]
fruits.each_with_index do |fruit, i|
puts "#{i + 1}: #{fruit}"
enddef factorial(n)
(1..n).reduce(1, :*)
end
puts factorial(5)begin
n = Integer("abc")
puts n
rescue ArgumentError => e
puts "Invalid number: #{e.message}"
ensure
puts "Done"
endcounts = Hash.new(0)
"banana".each_char { |ch| counts[ch] += 1 }
counts.each { |ch, n| puts "#{ch}: #{n}" }s = " Hello, World "
puts s.strip.upcase
puts s.strip.split(", ").inspect
puts [3, 1, 2].sort.inspectclass Person
attr_reader :name, :age
def initialize(name, age)
@name = name
@age = age
end
def describe
"#{@name} (#{@age})"
end
end
puts Person.new("Ada", 36).describenums = [1, 2, 3, 4, 5]
evens = nums.select { |n| n.even? }
doubled = evens.map { |n| n * 2 }
p doubled
puts "Sum: #{nums.sum}"words = ["pear", "apple", "fig"]
sorted = words.sort_by(&:length)
p sorted
puts words.max_by(&:length)Yes. CompileBytes runs your Ruby code in the browser with no local setup required—just write your script and execute it.
This compiler runs Ruby 3.0.1, so language features and standard library methods available up to that release are supported.
Use gets to read a line from standard input. Enter your input in the input/stdin panel before running, and call .chomp to strip the trailing newline.
Yes, running Ruby on CompileBytes is completely free with no account required.
The online compiler provides Ruby's standard library; third-party gems that need to be installed separately may not be available in the sandbox.