Chapter 11: Introducing Annotations
As mentioned in the previous chapter, macros can be a powerful tool for generating code in order to reduce duplication and keep your application DRY. However, one of the limitations of macros, especially those outsides of a macro definition, is that it is challenging to access data to use within the macro since it must be accessible at compile time, like an environmental variable or constant.
Neither of these are great options most of the time. In order to better solve this, we need to explore the next Crystal metaprogramming concept: annotations.
We will cover the following topics in this chapter:
- What are annotations?
- Storing data within annotations
- Reading annotations
By the end of this chapter, you should have a solid understanding of what annotations are and how to use them.