Skip to main content

Ruby

Ruby is a programming language made in 1995 by a Japanese guy nicknamed "Matz." 

His whole goal was to make a language that makes programmers happy, not just computers. So Ruby reads almost like plain English and doesn't make you jump through a ton of hoops.

Let's break down what that actually means, piece by piece.

Getting it on your computer

  • Windows: download something called RubyInstaller
  • Mac: it's already there, but you'll want to grab a newer version using Homebrew (brew install ruby)
  • Linux: use your normal package manager (apt install ruby etc.)
  • If you're doing a lot of Ruby stuff, there are tools (rbenv, RVM) that let you switch between different Ruby versions like changing outfits.

The basics: storing information

In Ruby, you just make up a name and shove a value into it — no need to say "this is a number" or "this is text" first:

name = "Alice"       # text (called a "string")
age = 25             # a whole number
height = 5.6         # a decimal number
is_student = true    # yes/no value

Ruby just figures out what type of thing it is. You don't have to tell it.

There's also this neat trick called string interpolation — instead of gluing text together awkwardly, you just drop a variable right into a sentence:

puts "My name is #{name} and I'm #{age} years old"

That #{} is Ruby saying "insert the variable's value right here."

Lists of stuff

An array is just an ordered list:

fruits = ["apple", "banana", "orange"]
fruits.push("grape")   # tack "grape" onto the end
fruits << "mango"      # same idea, different syntax

A hash is like a list of labeled boxes — you look things up by name instead of position:

person = { name: "Carol", age: 28, city: "San Francisco" }

Think of it like a mini dictionary: "name" points to "Carol," "age" points to 28, etc.

Making decisions

Standard if/else stuff, plus a fun Ruby-only twist called unless (which just means "if NOT"):

if age >= 18
  puts "Adult"
end

unless age < 18
  puts "Can vote"
end

Both of those say the same thing, just in different words — Ruby lets you write whichever reads more naturally to you.

Doing something repeatedly (this is Ruby's superpower)

Ruby is famous for how clean its loops look:

fruits.each do |fruit|
  puts "I like #{fruit}"
end

Translation: "For every fruit in the list, do this thing." The do |fruit| ... end part is just a mini block of instructions that runs once per item.

Or even simpler:

5.times { |i| puts "Count: #{i}" }

"Do this 5 times."

There are also handy shortcuts for common tasks:

  • map = transform every item (like squaring every number)
  • select = keep only the ones that match a condition
  • reduce = combine everything into one final value (like adding them all up)

Reusable chunks of code (methods)

A method is just a named block of instructions you can reuse:

def greet(name, greeting = "Hello")
  "#{greeting}, #{name}!"
end

Call greet("Alice") and it says "Hello, Alice!" — and you can even give it a default value (like "Hello") so you don't have to specify it every time.

Objects and classes (the "everything is an object" idea)

In Ruby, basically everything — numbers, text, true/false — is treated as an "object" with its own abilities. A class is like a blueprint for creating objects:

class Person
  def initialize(name, age)
    @name = name
    @age = age
  end

  def introduce
    "Hi, I'm #{@name}, #{@age} years old"
  end
end

alice = Person.new("Alice", 25)
puts alice.introduce

Think of Person as a cookie cutter, and alice as one actual cookie made from it.

Modules (shared toolkits)

A module is a bundle of reusable abilities you can plug into any class:

module Greetable
  def say_hello
    "Hello from #{self.class.name}!"
  end
end

class Student
  include Greetable
end

Now every Student automatically knows how to say_hello, without you rewriting that code.

When things go wrong

Ruby handles errors with begin/rescue, kind of like a safety net:

begin
  result = 10 / 0
rescue ZeroDivisionError => e
  puts "Error: #{e.message}"
ensure
  puts "This always runs"
end

"Try this. If it breaks in this specific way, catch it and handle it gracefully instead of crashing."

The big picture

Ruby was designed around the idea that code should be pleasant to write and easy to read — almost like a sentence. That's why it's popular for:

  • Web apps (especially with a framework called Ruby on Rails)
  • Automation scripts
  • Quick data processing tasks

If you want to actually try it: install Ruby, open up irb (Interactive Ruby — basically a playground where you type code and see results instantly), and mess around with the examples above. That's genuinely the fastest way it clicks.

Popular posts from this blog

How to Check if Someone is Connected to Your Machine in Linux

Picture this: you glance at your system monitor and notice your CPU is humming along even though you're not running anything demanding. Or maybe your internet feels sluggish for no obvious reason. A small, uneasy thought creeps in — is someone else on my machine right now? For Linux users, this isn't something you have to wonder about. Linux ships with a powerful set of built-in tools that let you see exactly who's connected, who's logged in, and what your network is doing at any given moment. You don't need to be a security expert to use them — you just need to know where to look. This guide walks you through the practical, no-nonsense steps to check for unauthorized connections on your Linux system, with real commands you can run right now. Why Monitoring Network Connections Matters Every device on a network — including your own Linux machine — communicates using an IP address. When another device or user connects to your system, that connection shows up as a trac...

How to Set Up a Linux Web Server and Host an HTML Page Easily

Setting up a web server on Linux means spending a fair amount of time in the terminal — Linux leans heavily on the command line rather than clicking through menus, so you'll be typing out instructions more often than not.  If you're new to this, it can feel a little intimidating at first, but the good news is you don't need to become a Linux wizard overnight. A handful of core commands will get you surprisingly far. A few you'll lean on constantly: cd — move between directories ls — see what's in the current directory mkdir — create a new folder nano or vim — edit files right there in the terminal sudo — run something with administrator privileges Get comfortable with these and you'll be able to navigate around, tweak configuration files, and install software without much trouble. You don't need to memorize everything — you just need to be confident enough to follow along with clear instructions, which is exactly what this guide aims to give you....

Linux Network Troubleshooting

If you've spent any time as a sysadmin — or honestly, just as someone who's had to fix their own home network at 11pm — you know that connectivity issues are one of the most common headaches out there. The good news is that a handful of core tools and a methodical approach can take you from "why isn't this working" to a root cause pretty quickly.  This guide walks through the essentials: configuring interfaces, managing routes, and diagnosing problems when things go sideways. Configuring Network Interfaces Your network interfaces are the actual bridge between your machine and the outside world, so getting them configured correctly is step one for any kind of reliable connectivity. Doing It Manually ifconfig is the old-school, tried-and-true tool for this on Unix-like systems. To see everything currently configured, run: ifconfig -a If you need to manually set up a specific interface — assigning an IP, a netmask, and bringing it online — it looks like this: ifconf...