Ruby is a popular, general-purpose programming language. You may have heard of it in connection to Ruby on Rails, one of the most popular web development frameworks in any programming language. Although much of Ruby's popularity comes from this connection, Ruby has many uses, including web scraping, static site generation, command-line tools, automation, DevOps, and data processing.
In this article, we'll take a look at how Ruby came to be and what makes it unique among programming languages.
What makes Ruby different?
Ruby is often called a "language of careful balance." It was released in 1995 by Yukihiro Matsumoto. Matsumoto had in-depth knowledge of multiple programming languages, including Perl, Smalltalk, Eiffel, Ada, and Lisp. He created Ruby to combine what he thought were the best features of these programming languages.
Ruby is a very flexible programming language that allows developers to alter how the language itself works. You can add functionality to core language features or even remove them if you need. Ruby is also a highly portable, cross-platform language. Code you write on one operating system will run on Linux, Mac OSX, and Windows. It will even run in UNIX, DOS, BeOS, OS/2, and more.
What is Ruby used for?
Ruby developers really love the language and have found many uses for it over the years. Check out some of the places Ruby is used in the list below.
Web development is one of Ruby's claims to fame because of the popular web development framework Ruby on Rails. Ruby on Rails was first released in 2005, and it changed how web development was done. Before frameworks like Ruby on Rails, developers had to spend a lot more time writing code to create a web application.
Ruby on Rails gives web developers everything they need to build a web application. Rails uses conventions that define the structure of every Rails app, so developers can spend less time configuring their projects. It has code generators that will generate parts of your application with a simple command, so developers write less code.
The rapid development that Ruby on Rails makes possible also made it a popular choice for startups because it allowed a small team of developers to build large applications quickly. Some sites you may have heard of that use Ruby on Rails include Github, Shopify, Kickstarter, Twitch, Instacart, Zendesk, SoundCloud, Ask.fm, Hulu, and Square.
Static site generation
Most websites use server-side code that generates HTML and serves it to your browser when you visit a page. There is no actual HTML file located at the URL you visited.
A static site generator still uses code, but it generates all the pages for a website at one time. Those pages are then deployed to a server, and when you visit a URL, you are served a static HTML file. Web sites built with static site generators are fast, efficient, secure, and easy to deploy. They're also useful for sites where content doesn't change frequently.
Written in Ruby, Jekyll was the first static site generator and is still the most popular. Github's founder, Tom Preston-Werner, created Jekyll and made it the default way to publish content on Github. The popularity of Jekyll took off after that, and many other programmers followed with their own static site generators in a multitude of programming languages.
DevOps and automation
Ruby is widely used for DevOps, automation, and website deployment. Heroku is a popular web app deployment platform that makes launching apps quick and easy, even for users who are unfamiliar with DevOps. Startups flocked to Heroku when it was first introduced because it allowed small teams to test, deploy, and stage their applications without a dedicated DevOps engineer. Now Heroku supports multiple languages, but originally it only supported Ruby.
Vagrant is a tool for managing virtual machines from command line. It allows developers to code and run projects developed for a specific operating system run on any operating system. For example, a developer can build services made to run on Linux on their Mac or Windows laptop and be sure that it will run correctly when deployed. Vagrant is written in Ruby, and Vagrant development environments must be configured with Ruby.
Chef and Puppet are tools that DevOps engineers use to automate and manage the configuration of web applications and servers. Using Chef or Puppet, engineers can define application environments with a simple configuration file and then use that configuration to launch instances of the application without any manual steps on any platform.
You can also use Ruby to build web servers. Passenger, Unicorn, and Puma are web servers written in Ruby. They process raw incoming HTTP requests, send them to correct backend web applications, and then handle the HTTP response sent back from the application. Ruby web application servers work hand in hand with web development frameworks written in Ruby.
Ruby is also a great language for data processing, cleaning, and filtering. Ruby's built-in map, reduce, and select functions are powerful tools used to solve many data processing problems.
Web scraping and crawling
Ruby has a wide variety of packages available that make extracting data from web pages a breeze. Ruby libraries like Vessel are used to crawl and download web pages. Nokogiri, another popular Ruby library, is then used to parse the HTML from the pages that have been crawled to extract specific parts of the page in a structured way to make it useable for data analysis.
Get started with Ruby
Ruby is a popular, flexible programming language that is in high demand in the marketplace. It can be used for web development, scripting, data processing, DevOps, static site generation, and more.
If you think Ruby is the programming language for you, a good place to start is with the Learn Ruby course. It will teach you the fundamentals of programming in Ruby. To learn one of the most popular web development frameworks and begin building your own web applications, check out the Ruby tutorial Learn Ruby on Rails. If you want to take your Rails education even further, we also have Learn Authentication with Ruby on Rails.