Method
To generate a method, use the Crygen::Types::Method class (here abbreviated as CGT::Method).
Output:
Included modules
Crygen::Modules::AnnotationCrygen::Modules::ArgCrygen::Modules::CommentCrygen::Modules::Scope
Writing code inside the method
Once the method is created, you can write code inside it using the #add_body method or by assigning to the body property.
method_type = CGT::Method.new("full_name", "String")
method_type.body = <<-CRYSTAL
return "John Doe"
CRYSTAL
Output:
It is recommended to use a heredoc when writing multiple lines of code.
Setting the method as abstract
You can set the created method as abstract by calling the #as_abstract method.
method_type = CGT::Method.new("full_name", "String")
method_type.as_abstract # This method is now abstract
Output:
Info
If you add code to the method body, this will not be shown after its code generation.