class Crygen::Types::Macro

Overview

A class that generates a macro

macro_type = CGT::Macro.new("example")
macro_type.add_arg("name")
puts macro_type.generate

Output:

macro example(name)
  puts {{ name }}
end

Defined in:

types/macro.cr

Constructors

Instance Method Summary

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

generate : String generate

Constructor Detail

def self.new(name : String) #

[View source]

Instance Method Detail

def add_arg(arg : String) : self #

Adds an argument to the macro.

macro_type = CGT::Macro.new("example")
macro_type.add_arg("name")

Output:

macro example(name)
end

Parameters:

  • arg : String Returns: an object class itself.

[View source]
def add_body(line : String) : self #

Adds a new line into the macro body.

macro_type = CGT::Macro.new("example")
macro_type.add_arg("name")
macro_type.add_body("puts {{ name }}")

Output:

macro example(name)
  puts {{ name }}
end

Parameters:

  • line : String Returns: an object class itself.

[View source]
def body=(body : String) : self #

Write the macro body.

macro_type = CGT::Macro.new("example")
macro_type.add_arg("name")
macro_type.body = "puts {{ name }}"

Output:

macro example(name)
  puts {{ name }}
end

Parameters:

  • body : String Returns: an object class itself.

[View source]
def generate : String #

Generates the macro. Returns: String


[View source]