class Crygen::Types::Enum

Overview

A class that generates an enumeration (enum).

enum_type = Crygen::Types::Enum.new("Person")
enum_type.add_constant("Employee")
enum_type.add_constant("Student")
enum_type.add_constant("Intern")
puts enum_type.generate

Output:

enum Person
  Employee
  Student
  Intern
end

Included Modules

Defined in:

types/enum.cr

Constructors

Instance Method Summary

Instance methods inherited from module Crygen::Modules::Annotation

add_annotation(annotation_type : Crygen::Types::Annotation) : self add_annotation

Instance methods inherited from module Crygen::Helpers::Annotation

add_link(name : String) : self add_link, as_deprecated(message : String) : self
as_deprecated : self
as_deprecated
, as_experimental(message : String) : self
as_experimental : self
as_experimental
, as_flags : self as_flags

Instance methods inherited from module Crygen::Modules::Method

add_method(method : Crygen::Types::Method) : self add_method

Instance methods inherited from module Crygen::Modules::Comment

add_comment(value : String) : self add_comment

Instance methods inherited from class Crygen::Interfaces::GeneratorInterface

generate : String generate

Constructor Detail

def self.new(name : String, type : String | Nil = nil) #

[View source]

Instance Method Detail

def add_constant(name : String, value : String | Nil = nil) : self #

Adds a constant into enum (name and value).

enum_type = Crygen::Types::Enum.new("Person")
enum_type.add_constant("Employee")

enum_type = Crygen::Types::Enum.new("Person")
enum_type.add_constant("Employee", 1)

Output: enum Person Employee end


[View source]
def generate : String #

Generates an enum.


[View source]