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::Method

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

Constructor Detail

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

[View source]

Instance Method Detail

def add_constant(name : String, value : String) : self #

Adds a constant into enum (name and value).

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

Returns: an object class itself.


[View source]
def add_constant(name : String) : self #

Adds a constant into enum (name only).

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

Output:

enum Person
  Employee
end

Returns: an object class itself.


[View source]
def generate : String #

Generates an enum. Returns: String


[View source]