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, add_annotations(*annotation_type : Crygen::Types::Annotation) : self add_annotations

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

always_inline : self always_inline, call_convention(name : String) : self call_convention, deprecated(message : String) : self
deprecated : self
deprecated
, experimental(message : String) : self
experimental : self
experimental
, extern : self extern, flags : self flags, link(name : String) : self link, no_inline : self no_inline, thread_local : self thread_local

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

add_method(method : Crygen::Types::Method) : self add_method, add_methods(*methods : Crygen::Types::Method) : self add_methods

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
enum Person
  Employee = 1
end

[View source]
def generate : String #

Generates an enum.


[View source]