A language tour
Code that reads like poetry — expressive, elegant, and joyful to write.
01 — Expressiveness
Ruby was designed for programmer happiness. Matz wanted a language that felt natural — like writing a sentence, not a specification.
# Ruby reads like a wish list 5.times { puts "Hello, world!" } # Asking real questions age = 17 puts age.odd? # → true (predicate methods end in ?) puts age.between?(10, 20) # → true # Unless is built-in puts "You're a minor" unless age >= 18 # One-liner conditionals feel like prose puts "Go to bed!" if Time.now.hour > 22
Method names end in ? when they return booleans — the language winks at you.
02 — Blocks & Iterators
Forget index variables and off-by-one errors. Ruby's blocks make looping a pleasure — and you can pass behaviour around like data.
"Blocks are chunks of code you can hand to a method and say: here, do this when you're ready."
— The Ruby philosophynumbers = [3, 1, 4, 1, 5, 9, 2, 6] # Transform every element squares = numbers.map { |n| n ** 2 } # → [9, 1, 16, 1, 25, 81, 4, 36] # Filter with intent evens = numbers.select(&:even?) # → [4, 2, 6] # Chain it all — pipeline style result = numbers .select { |n| n > 3 } .map { |n| n * 10 } .sum # → 200
&:method_name converts a symbol to a block — the shortest syntax for "call this method on each element."
03 — Open Classes
In Ruby, every class — even built-ins like Integer or String — can be reopened and extended. The language bends to your domain.
class Integer def factorial return 1 if self <= 1 self * (self - 1).factorial end def seconds; self; end def minutes; self * 60; end def hours; self * 3600; end end puts 5.factorial # → 120 puts 2.hours # → 7200 class String def palindrome? self == self.reverse end end puts "racecar".palindrome? # → true puts "ruby".palindrome? # → false
You didn't "monkey-patch" — you taught the number what a factorial means. That's a different mindset.
04 — Symbols & Hashes
Ruby's hashes and symbols feel lightweight and intentional — no boilerplate, just the structure you need.
# Modern hash syntax — clean and readable car = { make: "Porsche", model: "911", year: 1973, color: "Guards Red" } # Safe navigation — no more nil crashes user = nil puts user&.name # → nil (not an error!) # Destructuring with pattern matching (Ruby 3+) case car in { make: "Porsche", year: (1970..1979) => year } puts "Classic air-cooled from #{year}!" end # → Classic air-cooled from 1973!
The &. safe navigation operator is called "lonely operator" — because it guards you from nil in the loneliest of times.
05 — Modules & Mixins
Ruby avoids deep inheritance trees. Instead, modules let you compose behaviour cleanly — mix in exactly what you need.
module Driveable def drive puts "#{self.class} is driving!" end end module Electric def charge puts "Plugging in… ⚡" end end class Car include Driveable end class ElectricCar < Car include Electric end tesla = ElectricCar.new tesla.drive # → ElectricCar is driving! tesla.charge # → Plugging in… ⚡ # Enumerable mixin — mix it in, get 50+ methods free class Playlist include Enumerable def initialize(songs) @songs = songs end def each(&block) @songs.each(&block) end end pl = Playlist.new(["Bohemian Rhapsody", "Comfortably Numb", "Hotel California"]) puts pl.min # → Bohemian Rhapsody (alphabetically) puts pl.sort.first
Including Enumerable and defining one each method unlocks map, sort, min, group_by, flat_map and 40+ more for free.
06 — The Whole Picture
Every method returns something useful — chains flow left-to-right like a pipeline.
Even nil, true, and numbers are objects. No primitive types — it's objects all the way down.
"If it walks like a duck…" — Ruby cares what an object can do, not what it is.
"Hello #{name}" — weave values into strings without concatenation noise.
Ruby on Rails showed the world what convention-over-configuration looks like in practice.
Matz's goal: "Ruby is designed to make programmers happy." That's still in the language DNA.
07 — Dig Deeper
08 — Notable Contributors
09 — Notable Creations