Lessons
Crystal · Introductory
Crystal · Introductory. Ten lessons. Open-book quizzes. Lesson 1 free.
10 lessons · The Host · Lesson 1 free
Pass all ten lessons for the certificate. Sample · Claim

Lesson 1 · On the house
Hello, Crystal: run, build, interpolate
Write a .cr file, run it with crystal run, build a native binary, and print values with puts, print, p and #{} interpolation.

Lesson 2
Types, inference and union types
Number literals, Char, Symbol, typeof, union types such as Int32 | String, and how / and // divide.

Lesson 3
Control flow: if, unless, case, while
Branches are expressions, case matches ranges and types, and only nil and false are falsey.

Lesson 4
Methods: defaults, named args, overloads
Define methods with def, return the last expression, add type restrictions, defaults and named arguments, and overload by type.

Lesson 5
Arrays and ranges
Create, grow, slice and transform arrays with select, map and sum, and use inclusive and exclusive ranges.

Lesson 6
Hashes, tuples and named tuples
Store key-value pairs in Hash, read safely with []? and fetch, count with default values, and group fixed data in tuples.

Lesson 7
Nil safety: String?, if, try and not_nil!
Nil is a type, so String? must be checked before use: narrow with if, chain with try, default with ||, or assert with not_nil!.

Lesson 8
Classes and structs
Build classes with instance variables, initialize shorthand, getter and property, a custom to_s, and see how structs copy by value.

Lesson 9
Modules, inheritance and abstract classes
Share code with modules and include, inherit with <, require subclasses to implement abstract defs, and namespace helpers with def self.

Lesson 10
Blocks, procs and exceptions
Write methods that yield, capture blocks as procs, build procs with ->, and raise and rescue custom exceptions.
Sample certificate
Certificate of completion
Sign in to claim your certificate of completion.
Certificate
Finish all ten lessons, then sign in
Pass every lesson on this device (quizzes and checks). Then sign in or create an account to type your name and download the JPG.