Organizing Code in Classes and Modules

Variables and methods are powerful, but they need to be organized into larger structures to be very useful. As Crystal is a truly object-oriented language, classes are the main tool for doing that. Classes let you define combinations of methods and associated data, which you can then turn into objects with new. When you’ve built classes that work with each other, you can organize them into larger modules. Basic Crystal classes look much like Ruby classes, but Crystal makes some changes.

Class Basics

Classes group publicly visible methods and properties, and can have additional methods and variables inside of them to make things work smoothly. Class names start with an uppercase letter, but the rest of ...

Get Programming Crystal now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.