Ruby Koans
Ruby was designed to make programmers happy: its code reads naturally, and everything in it, even a number, is an object. It powers many web applications through its popular web framework, and it’s loved for scripts and tools too. Blocks, small pieces of code handed to methods, are everywhere. These koans cover objects, strings and collections, blocks and procs, classes and modules, and metaprogramming.
90 koans in 17 groups, tested with RSpec. Each is a small program whose tests fail: replace every ___ until they pass.
Awakening
How a koan checks your answers, and Ruby's first ideas: truth, nil, objects and equality.
Numbers
Integers of any size, floats, rationals, and the methods numbers come with.
Strings
Quotes and interpolation, string methods, slicing, mutation, formatting, heredocs, and characters.
- Quotes and interpolation
- String methods
- Indexing and slicing
- Mutation and frozen strings
- Formatting
- Heredocs
- Characters and bytes
Symbols and regular expressions
Symbols as names, and regular expressions for finding and changing text.
Ranges
Ranges of numbers, letters and dates of any kind, inclusive, exclusive or endless.
Arrays
Ordered collections: building, reading, changing, combining, sorting, transforming and searching.
Hashes
Key-value collections: reading, defaults, iterating, transforming and grouping.
Enumerable
The methods every collection shares, and enumerators, external and lazy.
Control flow
Conditions, case, pattern matching, and loops, all of which return values.
- Conditions
- case and when
- Pattern matching
- Loops
- Everything returns a value
- Case equality
- catch and throw
- Fibers
Methods
Defining methods, their arguments, return values, and conventions.
Blocks, procs and lambdas
Passing code to methods, and code as objects.
Classes
Defining classes: state, accessors, class-level members, inheritance, visibility, and how objects compare and print.
- Classes and instances
- Accessors
- Class methods and state
- Inheritance
- Visibility
- Printing and comparing
- Comparable
- Operators
- Copies
Modules
Mixins, namespaces, and module functions.
Structs and data
Quick classes for holding values.
Exceptions
Rescuing, cleaning up, retrying, and your own exceptions.
Metaprogramming
Code that inspects and writes code: sending messages, defining methods, and reopening classes.
Puzzles
Small programs that put the path together: read them closely and predict what they do.