← the guideThe Web Opens

§ 02 — Eras · 1995

Ruby

optimized for programmer happiness

Left: era context, features, and the 101 hello. Right: 3 core concepts, 3 deeper 201 lessons, the factorial specimen, and where Ruby lives today — each column scrolls on its own.

creators
Yukihiro “Matz” Matsumoto, 1995
status
alive · Rails, Shopify, GitHub
lineage
← Smalltalk-80

The problem it solves

Programmer joy: Matz optimized for human happiness — productivity first, elegance as a feature, not an accident.

The problem it carries

Slower than its peers, hospitable to monkey-patch chaos, and its fate married to a single framework.

Key features

blocks everywhere
Every method can take a block — iteration is a first-class idea, not a keyword.
everything is an object
Even nil and integers answer to the same protocol, so the language has one rule.
open classes
Reopen any class to add behaviour — a freedom that has also caused decades of grief.
metaprogramming
define_method and method_missing let code write code at run time.

101 — hello, world

Session one is the smallest program that still counts as speaking Ruby: what every tutorial prints first, in the dialect that mattered when the language arrived (1995).

the first program1995
puts "Hello, world"

101First contact — hello world and 3 ideas that define how Ruby reads. 201 — 3 lessons on mechanisms you meet after the factorial specimen: the sharp edges practitioners actually use.

101 — core concepts

3 fragments, each naming a habit of mind in Ruby. Read the note, then the code — together they are the 101 in one sitting.

01 — blocks

The loop’s body is handed to the method — iteration reads like prose.

%w[perch sundial].each do |app|
  puts app.capitalize
end

02 — everything is an expression

if, case, begin…end all return values; the language flows.

wage = 24
label = if wage > 20 then "senior" else "junior" end

03 — open classes

Any class can grow — the dynamism Rails is built on (and occasionally undone by).

class String
  def shout
    upcase + "!"
  end
end

"hello".shout

201 — going deeper

The 201 assumes you have read the 101 and the specimen. Each lesson is one mechanism — what it is for, how it looks in code, and the trap or payoff that makes Ruby distinctive at scale.

  1. blocks, procs and lambdas
  2. mixins and comparable modules
  3. metaprogramming and DSLs

blocks, procs and lambdas

A block is code handed to a method; a proc is the same thing as an object; a lambda is a proc with strict arity — three names for one idea.

add = ->(a, b) { a + b }
add.lambda?      #=> true  (strict arity)
add = proc { |a, b| a + b }

mixins and comparable modules

Enumerable and Comparable are modules mixed into core classes — inheritance replaced by composition, and the reason Ruby code reads like sentences.

class Ship
  include Comparable
  attr_reader :tons
  def <=>(other) tons <=> other.tons end
end

metaprogramming and DSLs

method_missing, define_method and blocks let a framework invent syntax — how Rails turned configuration into Ruby, and why Ruby looks unlike other languages.

def method_missing(name, *args)
  return super unless block_given?
  define_method(name) { |*a| instance_exec(*a, &Proc.new) }
end

The specimen — factorial

The block: iteration written as literature — each, select, map with the loop’s body handed over in place. Designed for programmer joy, and it shows.

the do block1995
%w[perch sundial graymail]
  .each { |app| puts app.capitalize }

Run it today

runruby fact.rb

Where it is now

Rails still launches companies; Shopify and GitHub run some of the largest Ruby codebases on Earth.