Course

Ruby from the ground up

A language designed to make programmers happy

  • Beginner
  • 13 chapters
  • 224 min read

Learn Ruby by writing it: values and variables, text, decisions, loops and ranges, arrays, hashes, blocks — the idea Ruby is built around — methods, classes, modules and mixins, errors and the standard library, ending with a small library that uses all of it.

What You'll Learn

  • Print output three ways and interpolate values into strings
  • Know that everything is an object, and ask values what they are
  • Tidy text with strip, split, join, gsub and format
  • Write conditions in Ruby, where only nil and false are false
  • Repeat work with while, until, ranges and each — and steer it with next and break
  • Question arrays with map, select, reject, sort and sum instead of loops
  • Store records and counts in hashes, with symbols as keys
  • Write and yield blocks, and use sort_by, group_by, inject and tally
  • Name work as methods, with defaults, splats, keyword arguments and guard clauses
  • Build classes with state, attributes and to_s, and inherit with super
  • Share behaviour with modules and get the whole of Enumerable from one method
  • Catch and raise exceptions, and use the standard library — JSON, dates, sets
  • Assemble a small library with classes, a mixin, blocks, errors and JSON

Prerequisites

  • No programming experience needed — this course starts at the first line
  • Any other language you know will make the early chapters quick

Course Content

  1. 01
    Your first Ruby

    What Ruby is, printing output three ways, numbers that behave, and the string interpolation you will use in every program after this one.

    Beginner · 14 min read

    Not started
  2. 02
    Values, and the names you give them

    Ruby has no primitives: everything is an object you can ask questions of. Numbers, text, symbols, nil, and the conversions between them.

    Beginner · 15 min read

    Not started
  3. 03
    Text, and the methods it brings

    Strings are objects with a large vocabulary: strip, split, join, gsub, the word-list literal, and format for lining numbers up in columns.

    Beginner · 16 min read

    Not started
  4. 04
    Decisions, and what counts as true

    if, elsif and unless, the modifiers that read like English, case for many branches, and Ruby's honest surprise: only nil and false are false.

    Beginner · 16 min read

    Not started
  5. 05
    Repetition, ranges, and saying no to a loop

    while and until, the times shortcut, each over a range, and the two words that steer a loop from inside: next and break.

    Beginner · 16 min read

    Not started
  6. 06
    Arrays: ordered lists you can question

    Building lists, reaching into them, and the methods that turn "loop over this and collect" into a single readable line.

    Intermediate · 17 min read

    Not started
  7. 07
    Hashes: values with names

    Key and value pairs, symbols as keys, fetch with a default, and the counting pattern that hashes were made for.

    Intermediate · 17 min read

    Not started
  8. 08
    Blocks: code you hand to a method

    The idea Ruby is built around — a method calls your block when it is ready — plus the collection toolbox that blocks unlock: sort_by, group_by, inject and tally.

    Intermediate · 19 min read

    Not started
  9. 09
    Methods: naming a piece of work

    Defining methods, the many shapes of an argument list, the return value that is already there, and the naming conventions that carry meaning.

    Intermediate · 17 min read

    Not started
  10. 10
    Classes: values that carry behaviour

    A blueprint with state inside: initialize, instance variables, the attribute shortcuts, to_s, and inheritance with super.

    Advanced · 19 min read

    Not started
  11. 11
    Modules: shared behaviour, and names for things

    A module cannot be built, and that is the point: it holds methods to be mixed into classes, and it gives namespaces so two Items can live in one program.

    Advanced · 18 min read

    Not started
  12. 12
    Errors, and the library you already have

    Exceptions as objects you can catch and raise, the begin/rescue/ensure shape, and a look at the standard library that ships with Ruby.

    Advanced · 18 min read

    Not started
  13. 13
    Putting it together: a small library

    A capstone that uses almost everything: classes with state, a mixin, Enumerable, blocks, sorted and grouped reports, a custom error, and JSON out of the standard library.

    Advanced · 22 min read

    Not started