
Crystal Programming
By :

Much of what we talked about and demonstrated in the last section can also be applied to types themselves. The one major benefit of iterating over types is that they are not constrained by the same limitation as instance variables are. In other words, you don't need to be in the context of a method in order to iterate over types. Because of this, the possibilities are almost endless!
You could iterate types within the context of another class to generate code, iterate on the top level to generate additional types, or even within a method to build out a sort of pipeline using annotations to define the order.
In each of these contexts, any data that is available at compile time could be used to alter how the code gets generated, such as environmental variables, constants, annotations, or data extracted from the type itself. All in all, it is a very powerful feature that has a lot of useful applications. But before we can start to explore some of those use cases...