class Crygen::Types::Method

Overview

A class that generates a method.

method_type = CGT::Method.new("major?", "Bool")
method_type.add_arg("age", "Int8", "22")
method_type.add_body("Hello world".dump)

Output:

def major?(age : Int8 = 22) : Bool
  "Hello world"
end

Included Modules

Defined in:

types/method.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::Modules::Arg

add_arg(name : String, type : String, value : String) : self
add_arg(name : String, type : String) : self
add_arg
, generate_args : String generate_args

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

as_private : self as_private, as_protected : self as_protected

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

add_comment(value : String) : self add_comment

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

generate : String generate

Constructor Detail

def self.new(name : String, return_type : String) #

[View source]

Instance Method Detail

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

Adds an annotation on a class.

method_type = CGT::Method.new("full_name", "String")
method_type.add_annotation(CGT::Annotation.new("Experimental"))

Output:

@[Experimental]
def full_name : String
end

Parameters:

  • annotation_type : Crygen::Types::Annotation Returns: an object class itself.

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

Add a code into method.

method_type = CGT::Method.new("full_name", "String")
method_type.add_body("Hello world".dump)

Output:

def full_name : String
  "Hello world"
end

Parameters:

  • body : String Returns: an object class itself.

[View source]
def generate : String #

Generates the methods. Returns: String


[View source]