Loading
All articles
Ruby 11 min read

What Is the Ruby Programming Language? A Simple Guide to the Language Built for Happiness

A friendly, jargon-free guide to Ruby, the programming language designed to make programmers happy. Learn why Ruby code reads like English, how Ruby on Rails powers sites like GitHub and Shopify, and where Ruby shines and struggles.

nbkhope
On this page

Most programming languages are designed around what's easiest for the computer. Ruby was designed around something different: what makes programmers happy.

Created in Japan in the 1990s, Ruby became world-famous thanks to Ruby on Rails, a toolkit for building websites that helped launch companies like GitHub, Shopify and Airbnb. This article explains, in plain language, what Ruby is, why its code reads almost like English, what Rails does, and where Ruby shines and struggles.

A language designed for joy

In 1993, a Japanese programmer named Yukihiro Matsumoto, known as "Matz", set out to create a language he'd enjoy using every day. He liked ideas from several existing languages and wanted to blend them into something both powerful and pleasant.

The name was a playful choice. A popular language at the time was called Perl, and the pearl is the birthstone for June. Matz picked the next month's birthstone: the ruby.

Ruby was first released to the public in 1995. Matz has often said that the goal of Ruby is to help programmers be productive and to enjoy programming. That idea shaped almost every decision in the language.

Ruby reads like English

The easiest way to feel Ruby's personality is to compare it with another language. Here's the same job, printing "Hello!" three times, in Java and in Ruby:

The same job in Java and in Ruby: say "Hello!" three times. Java takes 7 lines: a class, a main method, a for loop that counts rounds from 0 to 3, and a print statement. Ruby takes 1 line: 3.times, then puts "Hello!" inside curly braces. It reads almost like English: "3 times, say Hello!". Both print "Hello!" three times. Java spells out every detail; Ruby lets you say what you mean

Java spells out every detail: create a class, start a counter at zero, keep going while it's less than three, add one each time. Ruby simply says 3.times { puts "Hello!" }, which reads almost like a sentence: 3 times, say "Hello!" (puts means "put string", Ruby's way of printing a line).

This sentence-like style shows up everywhere in Ruby:

Ruby code often reads like a sentence, with real Ruby code and what Ruby answered. 5.even? asks "is 5 an even number?" and Ruby answers false. [].empty? asks "is this list empty?" and Ruby answers true. "hello".upcase means "make hello uppercase" and Ruby answers "HELLO". [3, 1, 2].sort.reverse means "sort the list, then reverse it" and Ruby answers [3, 2, 1]. words.tally means "count how often each word appears" and Ruby answers red 3 times, and so on. Everything in Ruby is an object, even a plain number, so 5 itself knows how to answer "are you even?". Names ending in ? are questions

Two details make Ruby feel friendly:

  • Everything is an object. In Ruby, even the number 5 is an object with its own abilities, so you can ask it directly: 5.even?. You don't need a separate "math helper" to find out.
  • Punctuation with meaning. Names ending in ? are questions that answer true or false, like empty?. Names ending in ! are a warning that something will be changed in place: name.upcase! turns the text stored in name into capital letters, instead of making a new copy.

What Ruby looks like

Here's the classic first program:

puts "Hello, world!"

That's the whole program. No classes, no main, no semicolons.

Like Java and C#, Ruby lets you describe a kind of thing as a class (a blueprint) and create objects from it. Here's a small car:

1class Car
2  attr_reader :color, :speed
3
4  def initialize(color)
5    @color = color
6    @speed = 0
7  end
8
9  def accelerate
10    @speed += 10
11  end
12
13  def brake
14    @speed = 0
15  end
16end
17
18my_car = Car.new("red")
19my_car.accelerate
20my_car.accelerate
21puts "My #{my_car.color} car is going #{my_car.speed} km/h"

When it runs, it prints: My red car is going 20 km/h. A few things to notice: def starts each action and end closes it, names starting with @ belong to the object, and #{...} drops a value right into a sentence.

And here's how you'd pick the adults out of a list of people and sort their names:

1people = [
2  { name: "Maria", age: 34 },
3  { name: "Ana", age: 17 },
4  { name: "Pedro", age: 25 },
5  { name: "Lucas", age: 15 },
6]
7
8adults = people
9  .select { |person| person[:age] >= 18 }
10  .map { |person| person[:name] }
11  .sort
12
13puts adults.join(", ") # Maria, Pedro

Select the people who are 18 or older, map each to their name, sort the names. The part between |...| names each item as Ruby goes through the list.

Ruby on Rails: the toolkit that made Ruby famous

For its first decade, Ruby was popular mostly in Japan. That changed in 2004, when a Danish programmer, David Heinemeier Hansson, released Ruby on Rails (usually just "Rails"). He had built it while creating Basecamp, a project-management app, and shared it for free.

Rails is a web framework: a ready-made structure for building websites. It handles the repetitive parts every website needs (talking to a database, showing pages, handling forms, logging users in) so developers can focus on what makes their site unique:

How a Ruby on Rails website answers a visit. The browser visits /products. The router decides who handles it. The controller, the manager, gathers what's needed. The model talks to the database. The view fills in the page template. The finished page is sent back to you. Rails gives every project the same layout and naming rules, "convention over configuration", so developers spend their time on the app, not on wiring

Think of a restaurant. The router is the host who sends you to the right table, the controller is the manager who coordinates your order, the model fetches ingredients from the pantry (the database), and the view plates the food nicely before it's served.

Rails is famous for two ideas:

  • Convention over configuration: instead of making developers configure everything, Rails assumes sensible defaults. If you have a model called Product, Rails already knows its data lives in a database table called products.
  • Don't repeat yourself: every piece of knowledge should live in one place, so changes only need to be made once.

A famous early video showed someone building a working blog in about 15 minutes with Rails, something that took days with other tools at the time. Startups loved it, and many of today's big tech companies began as Rails apps.

Where Ruby is used

Where Ruby is used. GitHub, where millions of programmers store their code. Shopify, online stores for millions of businesses. GitLab, another big home for code projects. Airbnb, which built its first website with Ruby on Rails. Basecamp and HEY, the company where Rails was born. Homebrew, the popular app installer for Mac. Ruby on Rails is a favorite of startups: it lets a small team build and launch a complete website quickly
  • GitHub, the world's biggest home for code, has run on Rails since it launched in 2008.
  • Shopify, which powers online stores for millions of businesses, runs one of the largest Rails applications in the world, and its engineers contribute heavily to Ruby itself.
  • GitLab, Basecamp and the email service HEY are Rails apps too.
  • Airbnb built its first website with Rails, and Twitter started on Rails in 2006 before moving much of its system to other languages as it grew.
  • Homebrew, the popular tool for installing software on a Mac, is written in Ruby.

Is it fast?

Ruby was designed for programmer happiness first, and speed second. We timed the same simple program, counting the prime numbers below 2 million, in four languages:

Speed test: easy to write, not the fastest. Counting the prime numbers below 2 million, timed from start to finish, measured for this article as the median of 5 runs on one Windows laptop. C: 0.41 seconds. JavaScript: 0.48 seconds. Ruby: 5.06 seconds. Python: 20.07 seconds. Versions: GCC 14, Node.js 26, Ruby 3.3 and Python 3.11. This Windows build of Ruby doesn't include YJIT, Ruby's built-in speed booster, which can make code like this noticeably faster on Linux and Mac

Ruby took about 5 seconds: much slower than C and JavaScript, though faster than Python on this particular test. Two things are worth knowing:

  • Ruby now includes YJIT, a speed booster built by engineers at Shopify that compiles busy code into fast machine code while the program runs. It wasn't available in the Windows version we tested, so Ruby on Linux or Mac can do noticeably better.
  • For most websites, raw number-crunching speed matters less than you'd think. A typical page spends much of its time waiting for the database or the network, and Rails' productivity often matters more than a few milliseconds.

The downsides

  • Not the fastest. For heavy calculations, games or other speed-critical work, languages like C++, Rust or Go are better fits.
  • Errors show up late. Ruby doesn't check the types of values before running, so some mistakes, like calling a method on something that doesn't have it, only appear while the program is running. Good automated tests (Ruby has a strong testing culture) help catch them. See Intro to RSpec and Test-Driven Development.
  • "Magic" can confuse beginners. Rails does a lot for you behind the scenes, which is great until you need to understand why something happened.
  • Less hype than before. Ruby was at the peak of its popularity in the late 2000s and early 2010s. It's still widely used and actively developed, but newer languages get more attention, and there are fewer Ruby jobs than JavaScript or Python ones.

A short history

A short history of Ruby, as a timeline. 1993: Yukihiro "Matz" Matsumoto starts Ruby in Japan. 1995: first public release. 2000: the first English book spreads Ruby abroad. 2004: Ruby on Rails is released. 2006: Twitter launches, built with Rails. 2008: GitHub launches, built with Rails. 2020: Ruby 3.0 arrives. 2022: the YJIT speed booster is ready for real use

A lovely tradition: a new version of Ruby is released every year on Christmas Day, December 25.

Should you learn Ruby?

  • Great reasons: you want to build web apps quickly, join a startup, or work on a Rails codebase like GitHub's or Shopify's. Ruby is also a gentle, fun first language: its readable style lets beginners focus on ideas instead of punctuation.
  • Good to know: Ruby is free and runs on Windows, Mac and Linux. It comes with irb ("interactive Ruby"), where you can type Ruby one line at a time and see the answer immediately, a great way to experiment.

A small glossary

  • Ruby: a programming language created by Yukihiro "Matz" Matsumoto, first released in 1995.
  • Matz: Ruby's creator, still leading its development.
  • Object: a thing with its own data and abilities. In Ruby, everything is one, even numbers.
  • Method: an action an object can perform, like upcase or even?.
  • Block: a chunk of code in { } or do ... end handed to a method, like { puts "Hello!" }.
  • Gem: a ready-made Ruby package you can add to a project.
  • Ruby on Rails (Rails): a framework for building websites quickly, released in 2004.
  • Router / controller / model / view: the parts of a Rails app that route a request, coordinate it, handle data and build the page.
  • Convention over configuration: following sensible defaults instead of configuring everything by hand.
  • YJIT: Ruby's built-in compiler that speeds up busy code while it runs.
  • irb: an interactive window for trying Ruby one line at a time.

Wrapping up

Ruby is the rare programming language designed around people rather than machines. Its code reads almost like English, everything in it is an object you can talk to directly, and small touches like question-mark methods make it feel friendly. Thanks to Ruby on Rails, that friendliness helped launch some of the web's best-known companies.

It isn't the fastest language and it's no longer the trendiest, but if you visit GitHub, shop at an online store built on Shopify, or install an app with Homebrew, you're still enjoying the work of a language built, as Matz intended, to make programming a joy.

Thanks for reading!

Know someone who would enjoy this? Send it their way.

More articles

Read next

9 min read

Intro to RSpec and Test-Driven Development

RSpec has become a popular choice as a testing framework for Ruby. Let us learn how to make unit tests and use a test-driven development approach to implement a program to calculate the factorial of a number.

nbkhope
9 min read

Ruby Hashes

An important data structure in Ruby is the hash. Hashes is a data structure of key-value pairs. In other programming languages, it might be called a dictionary or an associative array. If you know…

nbkhope
6 min read

Ruby Arrays

You can use arrays to group similar data into a single entity, instead of having to create multiple variables just to separate that same kind of data. Ruby makes it really convenient for you to work…

nbkhope

Comments

Be kind and specific. Comments with links from new accounts appear after a moderator reviews them.