Top 1,000 Features Creators Resources Extensions Blog Explorer Download
GitHub icon


< >

Ruby is an open source programming language created in 1995 by Yukihiro Matsumoto.

#9on PLDB 29Years Old 3mRepos
Download source code:
git clone

Try now: Riju ยท TIO ยท Replit

Ruby is a dynamic, reflective, object-oriented, general-purpose programming language. It was designed and developed in the mid-1990s by Yukihiro "Matz" Matsumoto in Japan. According to its creator, Ruby was influenced by Perl, Smalltalk, Eiffel, Ada, and Lisp. Read more on Wikipedia...

Example from Compiler Explorer:
# Type your code here, or load an example. def square(num) num * num end
Example from Riju:
puts "Hello, world!"
Example from hello-world:
#!/usr/bin/env ruby print "Hello World"
# Hello World in Ruby puts "Hello World!"
Example from Linguist:
module Foo end
Example from Wikipedia:
"Hello, World!".in_blue => "<span style=\"color: #00f\">Hello, World!</span>"
__ENCODING__ __FILE__ __LINE__ alias and BEGIN begin break case class def defined do else elsif END end ensure false for if in module next nil not or redo rescue retry return self super then true undef unless until when while yield

Language features

Feature Supported Token Example
Conditionals โœ“
Functions โœ“
While Loops โœ“
Case Sensitivity โœ“
Range Operator โœ“
Line Comments โœ“ #
# A comment
Print() Debugging โœ“ puts
puts "Hi"
Operator Overloading โœ“
Multiline Strings โœ“
Mixins โœ“
module A
   def a1
   def a2
module B
   def b1
   def b2
class Sample
include A
include B
   def s1
samp =
Iterators โœ“
(0...42).each do |n|
  puts n
File Imports โœ“
load 'filename.rb'
require 'filename'
require 'trig.rb'
Directives โœ“
coding: UTF-8
Here Document โœ“
Generators โœ“
# Generator from an Enumerator object
chars =['A', 'B', 'C', 'Z'])

4.times { puts }

# Generator from a block
count = do |yielder|
  i = 0
  loop { yielder.yield i += 1 }

100.times { puts }
Garbage Collection โœ“
MultiLine Comments โœ“ =begin =end
A comment.
Comments โœ“
# A comment
Classes โœ“
# A tiny Person class in Ruby:
class Person
  attr_accessor :name, :age, :   # getter and setter methods
  def initialize(name, age)
    @name = name
    @age = age

# Create a new Person object:
person ="John", 30)
puts person.age

# Change the age of the person:
person.age = 35
puts person.age
Constants โœ“
# Constants in Ruby being with a capital letter. Will throw a warning or error, depending on runtime settings.
Name = "John"
# Not a constant
name = "John"
Exceptions โœ“
def hello
 puts "Hello, World!"
   # start an exception handler
       raise "This is an exception"
   rescue => e
       puts "Exception caught: #{e}"
Assignment โœ“
pldb = 80766866
Booleans โœ“ true false
Integers โœ“
pldb = 80766866
Duck Typing โœ“
Regular Expression Syntax Sugar โœ“
puts "Hello World".match(/\w/)
Strings โœ“ "
"hello world"
Case Insensitive Identifiers X
Semantic Indentation X
Async Await X
Function Overloading X
Dispose Blocks Pattern X
Dependent types X
Enums X
Variable Substitution Syntax X

View source

- Build the next great programming language ยท About ยท Acknowledgements ยท Published by Breck's Lab