Ruby
Completed
-
Section 1: Getting Started
-
Section 2: Core Syntax
-
Section 3: Methods and Blocks
-
Section 4: Object-Oriented Ruby
-
Section 5: Metaprogramming
-
Section 6: Working with Data and Files
-
Section 7: Ruby Frameworks Overview
-
Section 8: Ecosystem and Testing
-
Section 9: Practical Projects
-
Section 10: Interview Practice
-
Section 11: Data Structures and Algorithms in Ruby
-
Section 12: More Practice Exercises
-
Section 13: Enumerable and Functional Style
-
Section 14: More OOP Practice
-
Section 15: More Testing
-
Section 16: Enumerable and Comparable Modules In Depth
-
Section 17: Ruby Standard Library: Core Utilities
-
Section 18: Ruby Standard Library: Data and Security
-
Section 19: Ruby Standard Library: CLI and Text
-
Section 20: Ruby Networking
-
Section 21: Ruby on Rails Deep Dive
-
Section 22: Ruby Metaprogramming Deep Dive
-
Section 23: Ruby Design Patterns
-
Section 24: Ruby Concurrency
-
Section 25: Ruby Testing Deep Dive
-
Section 26: Ruby Gems and Packaging
-
Section 27: Ruby Performance
-
Section 28: More Practice Exercises
-
Section 29: More Interview Practice
-
Section 30: Rails API Development
-
Section 31: Rails Authentication and Authorization
-
Section 32: Rails Testing Deep Dive
-
Section 33: Rails Performance
-
Section 34: Rails Deployment
-
Section 35: Sinatra and Lightweight Ruby Web Apps
-
Section 36: More Ruby Language Deep Dive
-
Section 37: Ruby 3.x Modern Features
-
Section 38: More Data Structures in Ruby
-
Section 39: More Practical Projects
-
Section 40: Ruby Ecosystem Tools
-
Section 41: More Practice and Review
-
Section 42: Final Practice and Mastery
-
Section 43: Ruby Interview Deep Dive
-
Section 44: Ruby Background Processing Deep Dive
-
Section 45: Ruby GraphQL
-
Section 46: Ruby Object Model Deep Dive
-
Section 47: Ruby Hanami Framework Overview
-
Section 48: Ruby gRPC and Protocol Buffers
-
Section 49: Ruby Data Processing
-
Section 50: Ruby Search Integration
-
Section 51: Ruby File Upload and Media
-
Section 52: Ruby Email and Notifications
-
Section 53: Ruby Admin Panels
-
Section 54: Ruby Feature Flags and Experimentation
-
Section 55: Ruby Monitoring and Observability
-
Section 56: Ruby Docker and Deployment Deep Dive
-
Section 57: Ruby Security Deep Dive
-
Section 58: More Advanced Metaprogramming
-
Section 59: More Final Projects
1: Installing Ruby and Using irb
Before we start writing actual files and building apps, we need to make sure your machine actually speaks Ruby. I've spent way too many hours of my career fighting with "system Rubies"—the versions that come pre-installed on macOS or Linux—because they're usually outdated or restricted by permissions. Let's see where you stand.
Checking the pulse of the system
First, let's just see if Ruby is already hanging around. Open your terminal and type this:
ruby -v
If you see something like ruby 3.2.2, you're in a good spot. But if you get a "command not found" or a version from 2015, we have a problem. I personally never use the system Ruby; I use a version manager like rbenv or rvm. Why? Because eventually, you'll need one project to run on Ruby 2.7 and another on 3.3, and trying to manage that manually is a nightmare. If you're missing it, go ahead and install rbenv and the latest stable Ruby version. Once that's done, run ruby -v again. When you see that 3.x version number, we're ready to actually play.
The sandbox approach
Now, I could have you create a main.rb file, save it, and run it from the terminal, but that's a slow way to learn. It's too much friction. Instead, I want you to try irb. It stands for "Interactive Ruby," and it's what we call a REPL (Read-Eval-Print Loop). Basically, it's a playground where Ruby executes your code the second you hit enter.
Type irb in your terminal and hit enter. You should see a prompt like irb(main):001:0>. We're now "inside" Ruby.
Calculating a coffee tab
Let's use this to solve a real-world problem. Say you're buying coffee for four coworkers. Each latte is $4.75. I'll just type the math straight in:
4 * 4.75
Ruby immediately spits back 19.0. It didn't ask for a filename or a "main" function; it just did the work. Now, let's say there's a 7% sales tax. I'll try to chain that on:
19.0 * 1.07
The result is 20.33. This is why I love irb. If I'm unsure how a specific method works or what a piece of data looks like, I don't write a whole program—I just jump in here and poke it until it tells me the truth.
Breaking things on purpose
Here is where most people get nervous: the error message. Let's intentionally mess up. I'll try to calculate a tip, but I'll forget to close my parentheses:
(20.33 * 0.20
Ruby doesn't give me an answer. Instead, it just gives me a > symbol on the next line. It's telling me, "You started something, but you didn't finish it. I'm still waiting." If I hit enter a few more times or type a closing parenthesis ), it will finally execute. But if I type something completely nonsensical, like this_is_not_a_variable, I'll get a NameError.
Don't fear the red text. In Ruby, the error message usually tells you exactly which line is the culprit and what it expected to find. The trick is to read the last line of the error first—that's usually where the actual problem is described.
📋 Practical Task
Calculating the Monthly Subscription Total
Open your terminal and launch irb. You are tasked with calculating the total cost of a software stack for a small team. Perform the following calculations directly in the REPL:
- Calculate the cost of 3 licenses for a tool that costs $12.99 per month.
- Add a one-time setup fee of $50.00 to that total.
- Apply a 15% discount to the entire sum (multiply the total by 0.85).
- Try to call a method that doesn't exist (like
calculate_magic_numbers) and observe the specific error Ruby returns.
Once you have the final discounted total, type exit to leave the irb session.
There are no comments for now.