Chapter 3: Object-Oriented Programming

Like many others, Crystal is an object-oriented language. As such, it has objects, classes, inheritance, polymorphism, and so on. This chapter will introduce you to the features of Crystal for creating classes and handling objects while guiding you through those concepts. Crystal is largely inspired by Ruby, which itself borrows a lot from the Small Talk language, which is famous for its powerful object model.

In this chapter, we will cover the following main topics:

  • The concept of objects and classes
  • Creating your own classes
  • Working with modules
  • Values and references – using structs
  • Generic classes
  • Exceptions

Technical requirements

To complete the tasks in this chapter, you will need the following: ...

Get Crystal Programming 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.