Comprehensive Ruby Programming

4.1 (8 reviews total)
By Jordan Hudgens
    Advance your knowledge in tech with a Packt subscription

  • Instant online access to over 7,500+ books and videos
  • Constantly updated with 100+ new titles each month
  • Breadth and depth in over 1,000+ technologies
  1. Introduction to the Ruby Programming Language

About this book

Ruby is a powerful, general-purpose programming language that can be applied to any task. Whether you are an experienced developer who wants to learn a new language or you are new to programming, this book is your comprehensive Ruby coding guide. Starting with the foundational principles, such as syntax, and scaling up to advanced topics such as big data analysis, this book will give you all of the tools you need to be a professional Ruby developer. A few of the key topics are: object-oriented programming, built-in Ruby methods, core programming skills, and an introduction to the Ruby on Rails and Sinatra web frameworks. You will also build 10 practical Ruby programs.

Created by an experienced Ruby developer, this book has been written to ensure it focuses on the skills you will need to be a professional Ruby developer. After you have read this book, you will be ready to start building real-world Ruby projects.

Publication date:
June 2017


Introduction to the Ruby Programming Language

Welcome to the Comprehensive Ruby Programming book! I'm excited to go through all the materials and walk you through this great programming language.

I've been a programmer for more than a decade, and I started Ruby about five years ago. Since then, I absolutely fell in love with Ruby for a wide array of reasons. As you learn the language you'll discover that you spend less time worrying about the syntax and more time coding, which adds to the fun. By the time you're finished with this course I hope you'll love this language as much as I do!

In this chapter, we'll take a high level view of the Ruby programming language, learn how to install it on your system, and get it up and running so you can start building Ruby programs. By the end of this chapter, you will have learnt the following:

  • Describe the high level concepts of the Ruby programming language
  • Construct the configuration to run Ruby programs
  • Define how to work with multiple Ruby versions

What is Ruby?

Ruby is an open source programming language, which means that it's free to use, and it was developed by a large community of developers.

So what can you do with Ruby? By leveraging the Ruby programming language you can build many different types of applications. If you're interested in building dynamic web applications you will most likely want to learn the Ruby on Rails web framework. Since Rails is built on top of Ruby, it's beneficial to understand how to program in Ruby before you can use Rails properly.


Popular sites that use Ruby

So what sites use Ruby?

  • A popular destination to watch TV shows and movies online
  • A video game-viewing site that was acquired by Amazon
  • A popular learning platform
  • A great entertainment site
  • An application that processes news and financial data to give financial insights to users
  • One of the most well-known Git repositories, GitHub enables developers from all over the world to host their code and collaborate with others

Now that you know the kind of applications that we can build with Ruby, let's get started!


Installing Ruby on a computer

Before we can start programming, you'll need to get Ruby installed on your system. I'm going to walk you through how you can install it on your computer regardless of your operating system, and I'll also give you alternate options if you don't want to install Ruby locally (however I highly recommend installing it).

Ruby language dashboard

Let's start by going to

When you click on the Download Ruby button, it will take you to the following page:

This page gives you information on how to install Ruby on your system.

If you are using the Windows operating system, follow these steps:

  1. Go to
  1. From this list, you can pick the stable version you want, I recommend that you go with the latest stable version. When you click on any of these links, the installer will run and you will be ready to go.

If you're using macOS, Ruby is already installed on your system. To check this follow these steps:

  1. I created a file called do_I_have_ruby.rb, which has only one line of code in it:
     puts "Yes, you have Ruby!"
  1. Next, go to your Terminal (make sure that you're in the same directory as your Ruby file) and run the file with the following command:
      ruby do_I_have_ruby.rb

This should display your string, if Ruby is properly installed:

If you don't feel comfortable creating and running a Ruby file like this, you can simply type irb into a Terminal window and if it opens up it means that you have Ruby. You can also type ruby -v to have the system show you what version of Ruby is installed.

One thing that you can do if you are using the Mac or Linux operating systems is to use the Ruby Version Manager (RVM). This gives you the flexibility to use different Ruby versions for different projects.

To install RVM, go to, and here you will find the Terminal commands that you can simply copy and paste in your Terminal:

Once you've installed RVM, type rvm list and this should list out all the Ruby versions on your system. If you want to change versions you can call the use command. For example, type in your Terminal to switch to Ruby version 2.4.0:

rvm 2.4.0

If you don't want to install Ruby on your local system, but still want to learn how to build Ruby programs, you can go to This should give you the list of languages available in the dashboard. When you click on Ruby, it will take you to a Terminal that will render all your Ruby code.

I tend to use this site if I have to quickly debug an algorithm or a confusing script. It's a great tool because you're able to get a side-by-side perspective on your code with its output:

So that's how you install Ruby! Now with that installed, you're ready to start learning how to build Ruby programs!


Installing different Ruby versions with RVM

If you're interested in using RVM to manage multiple versions of Ruby on your system, I want to give some more detailed instructions on how you can accomplish this:

  1. Start out by going to your Terminal and typing the following command:
      rvm list

If you have RVM installed, this will bring up all of the versions of Ruby that you have access to on your computer.

  1. If there is a version of Ruby that you want and that you don't already have on your system, simply type this in to the Terminal:
      rvm install 2.3.0  

Running this command will install the 2.3.0 version of Ruby for you:

You can do this for any versions of Ruby that are available via RVM. This makes it easy to ensure you're always using the most up-to-date version of the language. Using RVM is also helpful if you have different projects that utilize various versions of the language. For example, I have some legacy Ruby projects that use Ruby version 1.9.3, while all of my new projects use Ruby 2.3.0 (at the time of writing this guide).

By leveraging RVM, I can quickly switch between different versions of Ruby with a simple Terminal command. Alternatively, if you're not a fan of RVM, you can also use rbenv, which is a similar service.



In this chapter, we discussed what Ruby is and the popular applications that utilize the Ruby programming language. We also looked at the step-by-step approach of installing Ruby on your computer. With Ruby installed, we also acquired the tools needed to run Ruby programs and go through this book. We later extended our system's functionality and walked through how to install multiple versions of Ruby on our computers, which can be a helpful tool when working with multiple applications that require varying versions of the language.

In the next chapter, we will dive into how to work with variables in Ruby, which will give us the ability to store data and work with it in Ruby programs.

About the Author

  • Jordan Hudgens

    Jordan Hudgens is a full-stack developer and the founder of DevCamp and the Bottega Code School. As a developer for over the past 15 years, he specializes in Ruby on Rails, React, Vue.js, and TypeScript with a focus on API development. He has built applications for a wide variety of organizations, including Eventbrite and Quip. He has published and maintains multiple open-source NPM modules that help individuals automate the development process for JavaScript and TypeScript applications. Additionally, he has published over 30 courses, taught 42,000 students globally, and written several programming books.

    Browse publications by this author

Latest Reviews

(8 reviews total)
The book take time to appear in my account
Very good price and content.
I like the option of having both the book and videos.
Comprehensive Ruby Programming
Unlock this book and the full library for FREE
Start free trial