Ruby Concepts

Core Ruby language concepts explained in depth, one at a time.

Sort

Object Model & Metaprogramming

6

Design Patterns Built Into the Ruby Standard Library

Decorator, Observer, and Singleton already ship with Ruby as delegate, observer, and singleton — yet most codebases hand-roll all three. SimpleDelegator forwards everything you did not override (and lets you swap the target), DelegateClass(Array) is composition where you would have subclassed Array, and Singleton closes the dup/clone/Marshal leaks plus the thread race that a hand-written @instance ||= new always misses.

9

Ruby::Box: In-Process Namespace Isolation

Ruby 4.0's experimental container for isolating constants, monkey patches, and loaded libraries inside a single process — what it actually separates, and why it is namespace isolation rather than parallelism.

10

Method and UnboundMethod: Objects, Not Just Calls

obj.method(:name) hands you a callable value you can compose with >> and <<, curry, and introspect; unbind strips the receiver off so a module's implementation can be bind_call'd onto an object that never included it.

21

instance_eval, class_eval, and Building Internal DSLs

Why class_eval defines instance methods and instance_eval defines class methods, the _exec variants that fix the vanished-ivar trap, and how RSpec-style internal DSLs are built on the same self switch.

22

self, Singleton Classes, and Why Class Methods Don't Really Exist

self controls where @var lives and who receives a bare method call; singleton classes explain why 'class methods' are just methods defined on the class object itself.

23

Reflection and Introspection

method_missing vs. define_method, source_location, ObjectSpace, and the included/extended hooks behind ActiveSupport::Concern.

29

The Ruby Object Model and Method Lookup

How include, extend, and prepend actually change the method lookup chain, and why that matters more than memorizing the three keywords.

Concurrency

Collections & Blocks

Language Core & Idioms

3

Ruby Language Changes: 2.0 Through 4.0

Keyword-argument separation in 3.0, Ractors, Set becoming core, Prism as the default parser in 3.4, and *nil no longer converting via to_a in 4.0 — the version timeline other Ruby concepts on this platform assume you already know.

7

Typed Ruby: RBS and Sorbet

Ruby is dynamically but strongly typed, and two very different optional-typing layers sit on top: RBS ships with Ruby, keeps signatures in separate sig/*.rbs files, and never affects runtime — while Sorbet (Stripe) puts sig blocks inside your .rb files and checks them at runtime too, raising a real TypeError on a wrong argument.

12

Ruby Regex Beyond the Basics, and the ReDoS Trap

The regex features past /pattern/ — %r{} literals, match? vs. the $~ globals, /i /m /x /o, named groups, Hash and block substitution, Regexp.union — plus catastrophic backtracking: why it happens, what Ruby 3.2's linear-time matching does and does not cover, and how Regexp.timeout= turns a pinned CPU into a rescuable exception.

15

Common Ruby Gotchas: Silent Bugs Worth Knowing By Heart

The traps that produce no error at all: a setter without self. becoming a local, a misspelled initialize that never runs, {} vs do...end binding the block to the wrong call — plus source_location, sync = true, and freeze as the tools that turn silent bugs loud.

18

Duck Typing and Conversion Protocols

An object's type is the set of messages it responds to, not its class — plus the explicit (to_s) vs. implicit (to_str) conversion split that decides whether Ruby itself will treat your object as substitutable for a built-in type.

24

Exceptions as Control Flow: What They Actually Cost

The exception hierarchy, ensure/retry, and why catch/throw is the cheaper tool for jumping out of nested code that isn't an error.

25

Pattern Matching in Ruby

Deconstructing arrays, hashes, and custom objects with case/in — structural matching, binding, guards, and the pin operator.

Performance & Internals

Testing

Tooling & Debugging

Web & Frameworks