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 rubyetc.) - 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 conditionreduce= 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.