Crystal::Macros::ClassDef - Crystal 1.15.1

# class Crystal::Macros::ClassDef

- Crystal::Macros::ClassDef
- Crystal::Macros::ASTNode

##
Overview

A class definition.

Every class definition `node` is equivalent to:

    {% begin %}
      {% "abstract".id if node.abstract? %} {{ node.kind }} {{ node.name }} {% if superclass = node.superclass %}< {{ superclass }}{% end %}
        {{ node.body }}
      end
    {% end %}

##
Defined in:

compiler/crystal/macros.cr

##
Instance Method Summary

- #abstract? : BoolLiteral

  Returns whether this node defines an abstract class or struct.

- #body : ASTNode

  Returns the body of this type definition.

- #kind : MacroId

  Returns the keyword used to define this type.

- #name(*, generic_args : BoolLiteral = true) : Path | Generic

  Returns the name of this type definition.

- #splat_index : NumberLiteral | NilLiteral

  Returns the splat index of this type definition's generic type parameters.

- #struct? : BoolLiteral

  Returns `true` if this node defines a struct, `false` if this node defines a class.

- #superclass : ASTNode

  Returns the superclass of this type definition, or a `Nop` if one isn't specified.

- #type_vars : ArrayLiteral

  Returns an array of `MacroId`s of this type definition's generic type parameters.

### Instance methods inherited from class `Crystal::Macros::ASTNode`

!=(other : ASTNode) : BoolLiteral !=, ==(other : ASTNode) : BoolLiteral ==, class_name : StringLiteral class_name, column_number : StringLiteral | NilLiteral column_number, doc : StringLiteral doc, doc_comment : MacroId doc_comment, end_column_number : StringLiteral | NilLiteral end_column_number, end_line_number : StringLiteral | NilLiteral end_line_number, filename : StringLiteral | NilLiteral filename, id : MacroId id, is_a?(type : TypeNode) : BoolLiteral is_a?, line_number : StringLiteral | NilLiteral line_number, nil? : BoolLiteral nil?, raise(message) : NoReturn raise, stringify : StringLiteral stringify, symbolize : SymbolLiteral symbolize, warning(message : StringLiteral) : NilLiteral warning

##
Instance Method Detail

def abstract? : BoolLiteral #

Returns whether this node defines an abstract class or struct.

def body : ASTNode #

Returns the body of this type definition.

def kind : MacroId #

Returns the keyword used to define this type.

For `ClassDef` this is either `class` or `struct`.

def name(*, generic_args : BoolLiteral = true) : Path | Generic #

Returns the name of this type definition.

If this node defines a generic type, and generic_args is true, returns a `Generic` whose type arguments are `MacroId`s, possibly with a `Splat` at the splat index. Otherwise, this method returns a `Path`.

def splat_index : NumberLiteral | NilLiteral #

Returns the splat index of this type definition's generic type parameters.

Returns `nil` if this type definition isn't generic or if there isn't a splat parameter.

def struct? : BoolLiteral #

Returns `true` if this node defines a struct, `false` if this node defines a class.

def superclass : ASTNode #

Returns the superclass of this type definition, or a `Nop` if one isn't specified.

def type_vars : ArrayLiteral #

Returns an array of `MacroId`s of this type definition's generic type parameters.

On a non-generic type definition, returns an empty array.