class Crystal::Macros::ClassDef


A class definition.

Every class definition node is equivalent to:

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

Defined in:


Instance Method Summary

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.

[View source]
def body : ASTNode #

Returns the body of this type definition.

[View source]
def kind : MacroId #

Returns the keyword used to define this type.

For ClassDef this is either class or struct.

[View source]
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 MacroIds, possibly with a Splat at the splat index. Otherwise, this method returns a Path.

[View source]
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.

[View source]
def struct? : BoolLiteral #

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

[View source]
def superclass : ASTNode #

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

[View source]
def type_vars : ArrayLiteral #

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

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

[View source]