Chapter 12: Leveraging Compile-Time Type Introspection
In the previous chapters, we have mainly been using macros within types and methods themselves in order to access compile-time information or read annotations. However, this greatly reduces the effectiveness of macros to be able to dynamically react as new types are added or annotated. The next Crystal metaprogramming concept that we are going to take a look at is that of compile-time type introspection, which will cover the following topics:
- Iterating type variables
- Iterating types
- Iterating methods
By the end of this chapter, you should be able to create macros that generate code using instance variables, methods, and/or type information along with data read off of annotations.
Technical ...
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.