koans.app

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.

Start the path

Awakening

How a koan checks your answers, and Ruby's first ideas: truth, nil, objects and equality.

  1. Expectations
  2. Truth
  3. nil
  4. Everything is an object
  5. Equality
  6. Errors

Numbers

Integers of any size, floats, rationals, and the methods numbers come with.

  1. Integer arithmetic
  2. Big integers
  3. Floats
  4. Rationals
  5. Conversion
  6. Numeric methods

Strings

Quotes and interpolation, string methods, slicing, mutation, formatting, heredocs, and characters.

  1. Quotes and interpolation
  2. String methods
  3. Indexing and slicing
  4. Mutation and frozen strings
  5. Formatting
  6. Heredocs
  7. Characters and bytes

Symbols and regular expressions

Symbols as names, and regular expressions for finding and changing text.

  1. Symbols
  2. Regular expression basics
  3. scan and gsub
  4. Named captures

Ranges

Ranges of numbers, letters and dates of any kind, inclusive, exclusive or endless.

  1. Ranges
  2. Endless ranges and case
  3. Ranges in practice

Arrays

Ordered collections: building, reading, changing, combining, sorting, transforming and searching.

  1. Arrays
  2. Adding and removing
  3. Combining arrays
  4. Sorting
  5. Transforming
  6. Searching
  7. Destructuring and splat

Hashes

Key-value collections: reading, defaults, iterating, transforming and grouping.

  1. Hashes
  2. Default values
  3. Iterating and transforming
  4. Grouping and counting
  5. Merging and comparing

Enumerable

The methods every collection shares, and enumerators, external and lazy.

  1. reduce and sum
  2. Indexes and neighbors
  3. Enumerators
  4. Lazy
  5. Your own Enumerable

Control flow

Conditions, case, pattern matching, and loops, all of which return values.

  1. Conditions
  2. case and when
  3. Pattern matching
  4. Loops
  5. Everything returns a value
  6. Case equality
  7. catch and throw
  8. Fibers

Methods

Defining methods, their arguments, return values, and conventions.

  1. Defining methods
  2. Default and keyword arguments
  3. Splat arguments
  4. Method objects
  5. Naming conventions

Blocks, procs and lambdas

Passing code to methods, and code as objects.

  1. Blocks and yield
  2. Explicit blocks
  3. Procs and lambdas
  4. Closures
  5. Composition and currying

Classes

Defining classes: state, accessors, class-level members, inheritance, visibility, and how objects compare and print.

  1. Classes and instances
  2. Accessors
  3. Class methods and state
  4. Inheritance
  5. Visibility
  6. Printing and comparing
  7. Comparable
  8. Operators
  9. Copies

Modules

Mixins, namespaces, and module functions.

  1. Mixins
  2. prepend and extend
  3. Namespaces and constants
  4. Module functions

Structs and data

Quick classes for holding values.

  1. Struct
  2. Data

Exceptions

Rescuing, cleaning up, retrying, and your own exceptions.

  1. rescue, else and ensure
  2. The exception hierarchy
  3. Custom exceptions
  4. retry and raising again

Metaprogramming

Code that inspects and writes code: sending messages, defining methods, and reopening classes.

  1. Sending messages
  2. define_method
  3. method_missing
  4. Open classes
  5. Introspection

Puzzles

Small programs that put the path together: read them closely and predict what they do.

  1. FizzBuzz
  2. Word frequencies
  3. Anagrams
  4. Run-length encoding
  5. Roman numerals