Ruby

A readable, object-oriented scripting language, best known for web apps built with Rails.

Ruby is a dynamic, open source programming language designed to be simple and productive, with a syntax that is easy to read and write. It is widely used for web development through the Ruby on Rails framework, as well as for scripts and tooling.

  • Beginner
  • 11 lessons
Not started yet
Start lesson 1

Lessons

  1. Hello, Ruby!Write and run your first Ruby program, and learn the difference between puts, print and p.
  2. Variables & TypesLearn how variables, strings, numbers and symbols work in Ruby. Every value in Ruby is an object with methods, including nil, true and integers.
  3. Control FlowLearn if, unless, case and Ruby's loops. Ruby offers readable forms such as `unless` (if not), `until` (while not) and conditions at the end of a line.
  4. MethodsLearn how to define methods with `def`, pass arguments, and use blocks, procs and lambdas. A Ruby method returns the value of its last expression automatically.
  5. Arrays, Hashes & RangesLearn how to work with arrays, hashes and ranges. Built-in methods such as map, select and each handle most tasks you would otherwise write a loop for.
  6. Strings & RegexLearn the most useful String methods and how to search and transform text with regular expressions. All of this is built in, with nothing to import.
  7. Classes & OOPLearn how to define classes, create objects and use inheritance in Ruby. Helpers like `attr_accessor` generate getters and setters for you.
  8. Modules & MixinsLearn how modules group related methods and share them between classes. `include` adds a module's methods as instance methods and `extend` adds them as class methods; this is called a mixin.
  9. Error HandlingLearn how to raise and rescue exceptions so your program can recover from errors. `begin/rescue/ensure` works like try/catch/finally in other languages.
  10. Mini Project: CLI Password GeneratorBuild a command-line password generator that uses modules, classes, string handling and argument parsing together.
  11. Ruby CheatsheetSyntax, blocks, collections, and classes on one page.

Install it on your own computer

On macOS and Linux, install Ruby with a version manager such as rbenv or rvm so you can switch versions per project. On Windows, use RubyInstaller.

Bash
# Download and run RubyInstaller from rubyinstaller.org
# Choose the version with MSYS2/MINGW development toolchain (DevKit).

# Verify:
ruby -v
gem -v

What people build with Ruby

Learn the basics first, then pick up these tools when a project needs them.

Practical uses

  • Build productive web applications
  • Write readable automation and domain-specific languages
  • Create developer tooling and static sites
  • Prototype business ideas quickly

Projects to try

  1. CLI journal
  2. Sinatra URL shortener
  3. Rails booking system
  4. Custom static-site generator

Common tools and packages

RailsBundlerRSpecSidekiqSinatraRuboCopHanamiJekyll

Well-known software

GitHubShopifyBasecampDiscourseHomebrewJekyll