Skip to content

What is Ruby?

Updated Nov 30, 20264 min readBased on official documentation
What is Ruby?

In short

Ruby is a general-purpose programming language created to be easy to read and fun to write. Developers use it for web applications, scripts, and command-line tools. It focuses on programmer happiness and clear, expressive code.

What Ruby is

Ruby is a programming language. A programming language is a set of words and rules that you use to tell a computer what to do. Ruby is designed so that its code reads close to plain English. Many developers find it pleasant to write, which is one reason it has a loyal community.

Ruby code is interpreted. You write a file with the .rb extension, and a program called the Ruby interpreter reads and runs it line by line. You do not need to compile the code into a separate program before you run it. This makes the edit-and-run cycle quick, which helps when you are learning.

Ruby is object-oriented. That means most things in the language are objects, and each object has methods, which are actions it can perform. Even numbers and strings are objects. Calling a method looks like this: "hello".upcase returns "HELLO".

How it works

When you run a Ruby program, the interpreter reads your file, checks that it follows the language rules, and executes each instruction in order. If something goes wrong, it stops and shows an error message that includes the line number. Reading these messages is one of the most useful skills a new Ruby developer can build.

Ruby also has a large standard library. This is a collection of built-in code for tasks such as working with files, dates, and text. You can use these tools without installing anything extra. Beyond the standard library, the community shares packages called gems. A gem is a packaged piece of Ruby code that you can add to your project. The gem command and the Bundler tool help you install and manage them.

To try Ruby quickly, open a terminal and type irb. This starts the interactive Ruby shell, where you type an expression and see the result right away. Tools such as Pry offer a similar experience with extra features. The official documentation also lists browser-based options if you do not want to install anything yet.

When to use it

Ruby is most widely known for Ruby on Rails, a web framework. A web framework is a toolkit that handles common jobs for a website, such as routing requests, talking to a database, and rendering pages. Many startups and small teams have built their products with it, because a single developer can get a working site running quickly.

Ruby is also a good choice for scripts that automate routine work. You can use it to rename many files, parse log data, or call web services. Its text handling is strong, so it fits tasks that involve reading and transforming text.

Ruby is less common for work that needs very high speed or low-level control of memory, such as operating system code or game engines. Other languages are often better suited to those jobs. Choosing a tool depends on the project, the team, and the people who will maintain the code later.

A simple example

Here is a short Ruby program that greets a list of names:

names = ["Ada", "Grace", "Linus"]

names.each do |name|
  puts "Hello, #{name}!"
end

The array names holds three strings. The each method runs the block, which is the code between do and end, once for every item. The variable name holds the current item. The #{name} part inserts the value into the string. Save the file as hello.rb and run it with ruby hello.rb to see three greetings.

Common mistakes

Beginners often mix up = and ==. A single equals sign assigns a value to a variable, while a double equals sign compares two values. Using the wrong one can produce surprising results without an obvious error.

Another common issue is forgetting that Ruby has several versions. Code written for an older release may not run on a newer one. The official documentation lists versions and their release status, so check which version you are using before you follow an old tutorial.

Finally, many new developers try to learn Rails before they understand plain Ruby. Rails adds many conventions on top of the language. Spending a few weeks on the basics first makes the framework much easier to follow.

Where to learn next

The official Ruby website lists guides, tutorials, and reference material. For a complete beginner, the free book Learn to Program by Chris Pine is a common starting point, and the Ruby in Twenty Minutes tutorial is a short first step. If you are new to coding in general, you may also find our page on what a closure is helpful, since many Ruby features rely on blocks that work in a similar way. For a broader view of how languages handle memory while they run, read how garbage collection works.

When you are ready to read the reference, start with the official documentation at https://www.ruby-lang.org/en/documentation/ and pick one tutorial to follow from start to finish.

FAQ

Is Ruby hard to learn?

Ruby is considered approachable because its syntax reads close to English. Beginners still need time to learn concepts such as blocks and objects. A structured tutorial helps a lot.

What is the difference between Ruby and Ruby on Rails?

Ruby is the programming language. Ruby on Rails is a web framework written in Ruby that gives you a ready structure for building websites.

Do I need to install Ruby to try it?

Not necessarily. The official documentation points to options that let you try Ruby in your browser. Installing it locally gives you more control over your projects.

What is a gem in Ruby?

A gem is a packaged library of Ruby code that you can add to a project. The gem command and Bundler help you install and manage them.

Sources

This page is based on the official documentation below. Read it for full detail.

Ruby — official documentation ↗
blozhikDeveloper news from across the web, explained. Every story links to its original sources.