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

add_arg(name : String, type : String, value : String | Nil = nil) : 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::Interfaces::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

[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

[View source]
def generate : String #

Generates the methods.


[View source]