published: 2nd of August 2021
Enums group a related number of values and store the values internally as integers. Enums are good to use when the number of values are not too big.
# Define an Enum.
enum Bike
Specialized
Trek
Cannondale
Factor
end
# Access an Enum.
Bikes::Specialized # => Specialized
# Check the type of an Enum.
typeof(Bike::Specialized) # => Bike
# Access the Enum value
Bike::Specialized.value # => 0
# Check the type of the Enum value
typeof(Bike::Specialized.value) # => Int32
https://pragprog.com/titles/crystal/programming-crystal/
https://crystal-lang.org/reference/syntax_and_semantics/enum.html