What Is Ruby?

Learn the key features of Ruby, a free and open source software programming language, as well as how and when to use it.

What Is RubyRuby is a prominent free and open source software (FOSS) programming language. Due to its readability and simplicity, Ruby is a common choice for learning programming. Linux is the assumed development platform for Ruby, though an official Windows installer is available. MacOS includes Ruby by default.

Developers use programming languages like Ruby, Python, Java and C++ to create the code that allows applications to run. Developers write Ruby code and run the resulting application.

Yukihiro Matsumoto developed Ruby in 1995. The language has undergone three major iterations; the current version is 3.3.0 (as of December 2023). Like other languages, Ruby uses a three-digit number scheme to describe the major version, minor version and micro version.

Ruby Key Features

Ruby was designed to make developers happy. It offers many features to support this goal. Ruby is a high-level language, meaning programmers aren't stuck in the morass of memory management. Like many other languages, Ruby is object-oriented (objects are code modules made up of attributes and methods). Finally, Ruby doesn't need to be compiled. It's interpreted at runtime, making it very flexible.

Ruby emphasizes a relatively simple and readable syntax, enabling developers to focus on accomplishing tasks rather than using complex structures. Such simplicity also makes debugging Ruby code more straightforward.

One of the first things to know when starting with the Ruby programming language is the Ruby on Rails framework. You'll use this open source framework to create complete web applications with supporting databases. In turn, Rails uses Ruby to construct the necessary programming. It offers frequently used code snippets, saving time and reducing errors.

RubyGems Package Manager

Modern programming languages are extensible, allowing users to add functionality and customize the development process to meet their needs. Ruby applications and libraries are called "gems." The RubyGems package manager lets you add, update and troubleshoot these add-ons. Public repositories house the latest Ruby libraries.

Ruby Integrated Development Environments

Developers often use dedicated code-authoring applications to help manage their projects. These applications—called integrated development environments, or IDEs—offer features that help programmers avoid and correct mistakes.

Common IDE features include:

  • Syntax-checking specific to particular languages
  • Build tools to compile projects
  • Source control tools
  • Debugging error detection utilities

You can choose from many IDEs to begin your Ruby development. Some are paid, some are very feature-rich and some are browser-based. Here are some examples.

RubyMine

RubyMine is the go-to choice for many Ruby developers. It supports Ruby development and includes artificial intelligence (AI) features. JetBrains offers a 30-day trial period before you must pay for this IDE.

AWS Cloud9

AWS Cloud9 is a cloud-based IDE you work with through your web browser. It includes capabilities for writing and debugging code. Cloud9 allows for collaborative coding, an important feature in today's development environments. Cloud9 requires an active AWS subscription, and you will be billed for consumed resources.

Visual Studio Code

Microsoft Visual Studio Code is another viable option. You can add Ruby functionality to VS Code. It makes for a great platform for Windows and Mac users. Notice in the screenshot below that VS Code recognizes the Ruby syntax.

What Is Ruby ruby-in-vscode
Figure 1: Basic Ruby code in VS Code

 

Text Editors

You're not required to use a dedicated IDE with many bells and whistles. Standard text editors, like Vim, Emacs and Notepad++, will work fine for simple projects. These applications are extensible, allowing you to add features to manage your Ruby code better.

What Is Ruby helloworld
Figure 2: Basic Ruby code in the Vim text editor

 

When to Use Ruby

Those entering the programming field may find Ruby to be a friendly language to start with, especially if you are interested in web applications. Those interested in AI, data science or academic fields may be more drawn to Python.

Experienced developers may need to learn Ruby (and Ruby on Rails) to enhance their employability. It's a popular language with a broad sphere of influence (web apps certainly aren't going away).

Ruby Project Examples

An excellent way of learning a new programming language is to jump into a specific project. While this may initially sound intimidating, it's a practical way to see cause and effect with specific bits of code (including mistakes). Here are a few ideas for projects you can find on the web:

  • Simple tic-tac-toe game
  • Dynamic website
  • Event management software or website

Ruby is a general programming language, so your options are endless.

Common Concepts

Interpreted programming languages share many traits. Ruby relies on many of the same concepts and components as other languages. The following list discusses a few of these.

Libraries

Ruby uses pre-created code blocks to keep developers from having to rewrite standard code. These blocks are called libraries. Libraries may be added or removed from a Ruby installation using the RubyGem package manager. RubyGems.org serves as a repository. Libraries include:

  • Byebug: A tool for debugging Ruby applications
  • Minimagick: Functionality for adding upload capabilities to your application
  • NetHTTP: Generate simple HTTP GET requests for web apps
  • Logger: Control error output while testing Ruby code

Comments

Commenting code is more than just a good practice; it's essential to professional programming. Comments are notes to self or others explaining the options or reasons for a particular block of code. Like many other languages, Ruby uses the # character to specify comments.

Variables and Data Types

Variables allow developers to label information and reference it later. A developer might declare a user name, computer name, program or other value as a variable. Later in the code, that information can be pulled for use.

Ruby recognizes data types like text or numbers, allowing it to perform mathematical functions.

Operators

Operators act on Ruby data, such as performing mathematical functions on numbers.

Control structures

Control structures allow developers to manage what the code does. For example, the Ruby case control tests for conditions. Similarly, the while and for controls enable looping.

Get Started With Ruby

Begin by checking whether your system already has Ruby installed. Open a terminal application and type the ruby -v command to see version information or an error message indicating the program isn't found.

ruby -v

What Is Ruby ruby-v-on-mac
Figure 3: Checking the Ruby version

 

Install Ruby on Linux

Linux users can use their system's preferred package manager to install Ruby. The latest version is 3.3.0, but you can install older versions if necessary.

On Ubuntu, Debian and similar, type:

sudo apt-get install ruby-full

On Fedora, Red Hat and similar, type:

sudo dnf install ruby

Ruby is packaged for many other Linux platforms and package managers. Check the download page for more options. You can also add Ruby to the Linux Subsystem for Windows.

Install Ruby on Windows

One easy way to add Ruby and related packages to your Windows system is the RubyInstaller. Just download and run the installer.

If you prefer the Windows command-line package manager, run the following command (assuming the 3.3 version):

winget install RubyInstallerTeam.RubyWithDevKit.3.3

This command installs Ruby and a development kit that helps manage Ruby projects.

Install Ruby on macOS

MacOS typically includes the 2.0 version of Ruby by default. Use the ruby -v command to verify this. If you want to add a different version of Ruby, use the following Brew package manager command:

brew install ruby

Here's a chance to do a little basic Ruby programming. Try this simple Hello, World! application. I wrote the code using Vim on my Mac, but you can use any IDE or text editor (remember, don't use a word processor).

What Is Ruby helloworld
Figure 4: Adding a comment and basic Ruby commands to a text file

 

Save your changes and exit the text editor. Note the first line is a comment explaining the purpose of the code that follows it. Be sure to save your file with the .rb file extension.

Use the ruby command with the filename as the argument to run your code.

What Is Ruby helloworldrunning
Figure 5: Run the ruby command with the file name as the argument to execute the code

 

ruby hello.rb

Search online for another more complex Ruby project to continue to grow your skills.

Ruby vs. Other Programming Languages

Ruby is a popular programming language, especially for developing web apps. Ruby code is interpreted at runtime, as is JavaScript and Python. This makes Ruby different from languages like Java, C and C++, which must be compiled before running.

Ruby is frequently compared to Python. Both are common languages for new programmers to learn. Ruby tends to focus on web application development, while Python is often found in finance, science and AI environments. Ruby's web framework is Ruby on Rails, while Django is Python's framework. Finally, Ruby can be somewhat more difficult to debug than Python.

In the Stack Overflow 2023 Developer Survey, Ruby retains its position in the top five best-paying languages to learn.

What Is Ruby stackoverflow-top-paying
Figure 6: Ruby is one of the top-paying programming languages on the 2023 Stack Overflow Developer Survey

 

Ruby Advantages and Disadvantages

Here is a summary of the common advantages and disadvantages of Ruby.

The Advantages:

  • Ruby knowledge is in high demand
  • Readable syntax for interpretation and debugging
  • Not compiled
  • Extensive collection of libraries
  • Flexible feature set
  • Cross-platform support for Linux, Windows and macOS
  • Free and open source software (FOSS)

The Disadvantages:

  • Runs slower than compiled languages like C++ or Java
  • May not be as easy to debug as Python code
  • Features and support focus almost exclusively on web application development

Is Ruby a Good Option for You?

Ruby is a great option for new and experienced developers. Web application development skills are always in demand. Ruby itself continues to evolve, adding new capabilities and options. While the library system may not be as large as other languages, Ruby still has a robust code repository for any common project. Ruby's flexibility makes it a great option. While it may not be as fast as compiled code from languages like Java, it still plays an vital role with web apps. Are you ready to travel the Ruby development path?

 

Get the in-demand skills you need with CompTIA certifications and training solutions. Download the exam objectives to get started.

Email us at [email protected] for inquiries related to contributed articles, link building and other web content needs.

Read More from the CompTIA Blog

Leave a Comment