class

Crystal::Macros::ClassDef

Inherits Crystal::Macros::ASTNode

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 %}

Instance methods

abstract?

Returns whether this node defines an abstract class or struct.

Source
body

Returns the body of this type definition.

Source
kind

Returns the keyword used to define this type.

For ClassDef this is either class or struct.

Source
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.

Source
splat_index

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.

Source
struct?

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

Source
superclass

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

Source
type_vars

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

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

Source