abstract class Crystal::Type

Overview

Abstract base class of all types

Included Modules

Direct Known Subclasses

Defined in:

compiler/crystal/codegen/types.cr
compiler/crystal/interpreter/c.cr
compiler/crystal/semantic/cover.cr
compiler/crystal/semantic/lib.cr
compiler/crystal/semantic/method_lookup.cr
compiler/crystal/semantic/method_missing.cr
compiler/crystal/semantic/path_lookup.cr
compiler/crystal/semantic/restrictions.cr
compiler/crystal/semantic/suggestions.cr
compiler/crystal/semantic/type_intersect.cr
compiler/crystal/semantic/type_lookup.cr
compiler/crystal/semantic/type_merge.cr
compiler/crystal/types.cr

Constant Summary

ONE_ARG = [Arg.new("a1")]
SuggestableDefName = /\A[a-z_]/

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from module Crystal::Annotatable

add_annotation(annotation_type : AnnotationType, value : Annotation) add_annotation, all_annotations : Array(Annotation) | Nil all_annotations, annotation(annotation_type : AnnotationType) : Annotation | Nil annotation, annotations(annotation_type : AnnotationType) : Array(Annotation) | Nil
annotations : Hash(AnnotationType, Array(Annotation)) | Nil
annotations
, annotations=(annotations : Hash(AnnotationType, Array(Annotation)) | Nil) annotations=

Instance methods inherited from class Reference

==(other : self)
==(other : JSON::Any)
==(other : YAML::Any)
==(other)
==
, dup dup, hash(hasher) hash, initialize initialize, inspect(io : IO) : Nil inspect, object_id : UInt64 object_id, pretty_print(pp) : Nil pretty_print, same?(other : Reference) : Bool
same?(other : Nil)
same?
, to_s(io : IO) : Nil to_s

Constructor methods inherited from class Reference

new new, unsafe_construct(address : Pointer, *args, **opts) : self unsafe_construct

Class methods inherited from class Reference

pre_initialize(address : Pointer) pre_initialize

Instance methods inherited from class Object

! : Bool !, !=(other) !=, !~(other) !~, ==(other) ==, ===(other : JSON::Any)
===(other : YAML::Any)
===(other)
===
, =~(other) =~, as(type : Class) as, as?(type : Class) as?, class class, dup dup, hash(hasher)
hash
hash
, in?(collection : Object) : Bool
in?(*values : Object) : Bool
in?
, inspect(io : IO) : Nil
inspect : String
inspect
, is_a?(type : Class) : Bool is_a?, itself itself, nil? : Bool nil?, not_nil!(message)
not_nil!
not_nil!
, pretty_inspect(width = 79, newline = "\n", indent = 0) : String pretty_inspect, pretty_print(pp : PrettyPrint) : Nil pretty_print, responds_to?(name : Symbol) : Bool responds_to?, tap(&) tap, to_json(io : IO) : Nil
to_json : String
to_json
, to_pretty_json(indent : String = " ") : String
to_pretty_json(io : IO, indent : String = " ") : Nil
to_pretty_json
, to_s(io : IO) : Nil
to_s : String
to_s
, to_yaml(io : IO) : Nil
to_yaml : String
to_yaml
, try(&) try, unsafe_as(type : T.class) forall T unsafe_as

Class methods inherited from class Object

from_json(string_or_io : String | IO, root : String)
from_json(string_or_io : String | IO)
from_json
, from_yaml(string_or_io : String | IO) from_yaml

Macros inherited from class Object

class_getter(*names, &block) class_getter, class_getter!(*names) class_getter!, class_getter?(*names, &block) class_getter?, class_property(*names, &block) class_property, class_property!(*names) class_property!, class_property?(*names, &block) class_property?, class_setter(*names) class_setter, def_clone def_clone, def_equals(*fields) def_equals, def_equals_and_hash(*fields) def_equals_and_hash, def_hash(*fields) def_hash, delegate(*methods, to object) delegate, forward_missing_to(delegate) forward_missing_to, getter(*names, &block) getter, getter!(*names) getter!, getter?(*names, &block) getter?, property(*names, &block) property, property!(*names) property!, property?(*names, &block) property?, setter(*names) setter

Constructor Detail

def self.merge!(type1 : Type, type2 : Type) : Type #

[View source]
def self.merge!(types_or_nodes) : Type #

[View source]
def self.new(program : Program) #

[View source]

Class Method Detail

def self.common_descendent(type1 : TupleInstanceType, type2 : TupleInstanceType) #

[View source]
def self.common_descendent(type1 : NamedTupleInstanceType, type2 : NamedTupleInstanceType) #

[View source]
def self.common_descendent(type1 : ProcInstanceType, type2 : ProcInstanceType) #

[View source]
def self.common_descendent(type1 : NonGenericModuleType | GenericModuleInstanceType, type2 : AliasType) #

[View source]
def self.common_descendent(type1 : NonGenericModuleType | GenericModuleInstanceType, type2 : UnionType) #

[View source]
def self.common_descendent(type1 : NonGenericModuleType | GenericModuleInstanceType, type2 : VirtualType) #

[View source]
def self.common_descendent(type1 : NonGenericModuleType | GenericModuleInstanceType, type2 : GenericClassType) #

[View source]
def self.common_descendent(type1 : GenericModuleInstanceType, type2 : GenericModuleInstanceType) #

[View source]
def self.common_descendent(type1 : GenericModuleInstanceType, type2 : GenericModuleType) #

[View source]
def self.common_descendent(type1 : NonGenericModuleType | GenericModuleInstanceType, type2 : Type) #

[View source]
def self.common_descendent(type1 : GenericClassInstanceType, type2 : GenericClassType) #

[View source]
def self.common_descendent(type1 : GenericClassType, type2 : GenericClassInstanceType) #

[View source]
def self.common_descendent(type1 : GenericInstanceType, type2 : GenericInstanceType) #

[View source]
def self.common_descendent(type1 : MetaclassType, type2 : VirtualMetaclassType) #

[View source]
def self.common_descendent(type1 : VirtualMetaclassType, type2 : MetaclassType) #

[View source]
def self.common_descendent(type1 : VirtualMetaclassType, type2 : VirtualMetaclassType) #

[View source]

[View source]

[View source]
def self.common_descendent(type1 : UnionType, type2 : Type) #

[View source]
def self.common_descendent(type1 : AliasType, type2 : AliasType) #

[View source]
def self.common_descendent(type1 : AliasType, type2 : Type) #

[View source]
def self.common_descendent(type1 : TypeDefType, type2 : UnionType) #

[View source]
def self.common_descendent(type1 : TypeDefType, type2 : AliasType) #

[View source]
def self.common_descendent(type1 : TypeDefType, type2 : Type) #

[View source]
def self.common_descendent(type1 : VirtualType, type2 : VirtualType) #

[View source]
def self.common_descendent(type1 : VirtualType, type2 : AliasType) #

[View source]
def self.common_descendent(type1 : VirtualType, type2 : UnionType) #

[View source]
def self.common_descendent(type1 : VirtualType, type2 : Type) #

[View source]
def self.common_descendent(type1 : NilType, type2 : VoidType) #

[View source]
def self.common_descendent(type1 : GenericClassType, type2 : GenericClassType) #

[View source]
def self.common_descendent(type1 : Type, type2 : AliasType) #

[View source]
def self.common_descendent(type1 : Type, type2 : UnionType) #

[View source]
def self.common_descendent(type1 : Type, type2 : VirtualType) #

[View source]
def self.common_descendent(type1 : Type, type2 : GenericClassType) #

[View source]
def self.common_descendent(type1 : Type, type2 : Type) #

Given two types T and U, returns a common descendent V such that V <= T and V <= U. This is the same as:

typeof(begin
  x = uninitialized T
  x.is_a?(U) ? x : raise ""
end)

except that nil is returned if the above produces NoReturn.


[View source]

[View source]

[View source]
def self.least_common_ancestor(type1 : GenericClassType, type2 : ClassType | GenericClassInstanceType) #

[View source]
def self.least_common_ancestor(type1 : NonGenericModuleType | GenericModuleInstanceType | GenericClassType, type2 : Type) #

[View source]
def self.least_common_ancestor(type1 : ClassType | GenericClassInstanceType, type2 : GenericClassType) #

[View source]
def self.least_common_ancestor(type1 : Type, type2 : NonGenericModuleType | GenericModuleInstanceType | GenericClassType) #

[View source]
def self.least_common_ancestor(type1 : TupleInstanceType, type2 : TupleInstanceType) #

[View source]
def self.least_common_ancestor(type1 : NamedTupleInstanceType, type2 : NamedTupleInstanceType) #

[View source]
def self.least_common_ancestor(type1 : ClassType | GenericClassInstanceType, type2 : ClassType | GenericClassInstanceType) #

[View source]
def self.least_common_ancestor(type1 : Type, type2 : Type) #

Given two non-union types T and U, returns their least common ancestor LCA(T, U) such that the following properties are satisfied:

  • LCA(T, U) is never a union;
  • LCA(T, U) is never virtual, since #type_combine takes care of this;
  • T <= LCA(T, U) and U <= LCA(T, U);
  • for any type V, if T <= V and U <= V, then LCA(T, U) <= V;
  • LCA is commutative up to equivalence; that is, if V = LCA(T, U) and W = LCA(U, T), then V <= W and W <= V;
  • LCA is associative up to equivalence.

If such a type exists and this type can be used as a virtual root (see Program#virtual_root?), then T | U is precisely the virtual type of LCA(T, U). Otherwise, T | U is an irreducible union and this method should return nil.

The above applies only if T and U are unequal; this is guaranteed by Program#add_type, so T | T produces a non-virtual type. However, this method should not break in case it recursively calls itself with two identical types.


[View source]
def self.merge(nodes : Enumerable(ASTNode)) : Type | Nil #

[View source]
def self.merge(types : Array(Type)) : Type | Nil #

[View source]

Instance Method Detail

def abstract? #

Returns true if this type is abstract.


[View source]
def abstract_leaf? #

Returns true if this type is abstract and it has no concrete subclasses. This can happen if this type has abstract subclasses, or non-abstract generic subclasses without instantiations.


[View source]
def add_including_type(mod) #

[View source]
def add_instance_var_initializer(name, value, meta_vars) #

[View source]
def add_subclass(subclass) #

[View source]
def all?(&) #

Yields self and returns true if the block returns a truthy value. UnionType overrides it and yields all types in turn and returns true if for each of them the block returns true.


[View source]
def all_class_vars #

[View source]
def all_instance_vars #

[View source]
def all_instance_vars_count #

[View source]
def all_subclasses #

Returns all subclasses of this type, including subclasses of subclasses recursively.


[View source]
def allowed_in_lib? #

Returns true if this type can be used in a lib declaration: in a fun, struct/union member, or typedef.


[View source]
def allows_instance_vars? #

Returns true if this type can have instance vars. Primitive types, and types like Reference and Object, can't have instance vars.


[View source]
def ancestors #

[View source]
def append_cover(array) #

[View source]
def append_to_expand_union_types(types) #

[View source]
def bool_type? #

[View source]
def can_be_stored? #

Returns true if this type can be assigned to an instance or class variable, or used in a generic type argument.

As of now, abstract base type such as Object, Reference, Value, Int, and unbound generic types such as Array(T), can't be stored.


[View source]
def check_method_missing(signature, call) #

[View source]
def check_restriction_exception #

Checks whether an exception needs to be raised because of a restriction failure. Only overwritten by literal types (NumberAutocastType and SymbolAutocastType) when they produce an ambiguous call.


[View source]
def class? #

[View source]
def class_var_owner #

Returns the type that owns class vars for a type.

This method returns self, but subclasses might override. For example, a metaclass' class_var_owner is the instance type.


[View source]
def class_vars #

[View source]
def compatible_with?(type) #

[View source]
def cover #

[View source]
def cover_size #

[View source]
def declare_instance_var(name, type : Type, annotations = nil) #

[View source]
def define_method_from_method_missing(method_missing, signature, original_call) #

[View source]
def defs : Hash(String, Array(DefWithMetadata)) | Nil #

Returns the methods defined in this type, indexed by their name. This does not include methods defined in ancestors.


[View source]
def depth #

[View source]
def devirtualize #

Returns the non-virtual type of a given type (returns self if self is already non-virtual)


[View source]
def doc : String | Nil #

Returns any doc comments associated to this type.


[View source]
def double_variadic? #

[View source]
def each_cover(&) #

[View source]
def each_namespace(& : ModuleType -> ) : Nil #

Yields each namespace this type belongs to, excluding the Program itself.


[View source]
def extern? #

Returns true if this is an extern C struct or union (#extern_union? tells which one)


[View source]
def extern_union? #

Returns true if this is an extern C union (#extern? will be true too)


[View source]
def ffi_arg_type : FFI::Type #

Returns an FFI::Type to be used as a C function argument.


[View source]
def ffi_type : FFI::Type #

Must return an FFI::Type for this type.


[View source]
def filter_by(other_type : Type) #

[View source]
def filter_by_responds_to(name) #

[View source]
def generic_nest #

[View source]
def generic_type #

[View source]
def get_instance_var_initializer(name) #

[View source]
def has_def?(name) #

[View source]
def has_def_without_parents?(name) #

[View source]
def has_in_type_vars?(type) #

[View source]
def has_inner_pointers? #

Returns true if the type has inner pointers. This is useful to know because if a type doesn't have inner pointers we can use malloc_atomic instead of malloc in Pointer.malloc for a tiny performance boost.

This behaviour is documented in Pointer.malloc


[View source]
def has_instance_var_initializer?(name) #

[View source]
def has_protected_access_to?(type, allow_same_namespace = true) #

Determines if self can access type assuming it's a protected access. If allow_same_namespace is true (the default), protected also means the types are in the same namespace. Otherwise, it means they are just in the same type hierarchy.


[View source]
def implements?(other_type : Type) #

[View source]
def implicitly_converted_in_c_to?(expected_type) #

Returns true if this type can be implicitly converted to expected_type when this is a lib fun argument, without involving to_unsafe or numeric conversions. For example nil can be passed to an argument of type pointer.


[View source]
def includes_type?(type) #

[View source]
def including_types #

[View source]
def index_of_instance_var(name) #

[View source]
def inspect(io : IO) : Nil #
Description copied from class Reference

Appends a String representation of this object which includes its class name, its object address and the values of all instance variables.

class Person
  def initialize(@name : String, @age : Int32)
  end
end

Person.new("John", 32).inspect # => #<Person:0x10fd31f20 @name="John", @age=32>

[View source]
def instance_type #

[View source]
def instance_vars #

[View source]
def leaf? #

Returns true if this type has no subclasses.


[View source]
def llvm_name(io) #

[View source]
def llvm_name #

[View source]
def locations : Array(Location) | Nil #

Returns all locations where this type is declared


[View source]
def lookup_class_var(name) #

[View source]
def lookup_class_var?(name) #

[View source]
def lookup_defs(name : String, lookup_ancestors_for_new : Bool = false) #

[View source]
def lookup_defs(name : String, all_defs : Array(Def), lookup_ancestors_for_new : Bool | Nil = false) #

[View source]
def lookup_defs_with_modules(name) #

[View source]
def lookup_defs_without_parents(name : String, all_defs : Array(Def)) #

[View source]
def lookup_defs_without_parents(name : String) #

[View source]
def lookup_first_def(name, block) #

[View source]
def lookup_instance_var(name : String) #

[View source]
def lookup_instance_var(node : InstanceVar | ReadInstanceVar | MetaVar) #

[View source]
def lookup_instance_var?(name : String) #

[View source]
def lookup_macro(name, args : Array, named_args) #

Looks up a macro with the given name and matching the given args and named_args. Returns:

In the case of DefInMacroLookup, it means that macros shouldn't be looked up in implicit enclosing scopes such as Object or the Program.


[View source]
def lookup_macros(name) #

Looks up macros with the given name. Returns:

  • an Array of Macro if found
  • nil if not found
  • DefInMacroLookup if not found and some Defs were found instead

[View source]
def lookup_matches(signature, owner = self, path_lookup = self, matches_array = nil, analyze_all = false) #

[View source]
def lookup_matches_with_modules(signature, owner = self, path_lookup = self, matches_array = nil, analyze_all = false) #

[View source]
def lookup_matches_without_parents(signature, owner = self, path_lookup = self, matches_array = nil, analyze_all = false) #

[View source]
def lookup_method_missing #

[View source]
def lookup_name(name) #

[View source]
def lookup_new_in_ancestors? #

Should .new be looked up in ancestors?

This is true if this type doesn't define any initialize methods.


[View source]
def lookup_path(path : Path, lookup_in_namespace = true, include_private = false, location = path.location) : Type | ASTNode | Nil #

Looks up a path (for example: Foo::Bar::Baz) relative to self.

For example, given:

class Foo
  class Bar
    class Baz
    end
  end
end

If self is Foo and we invoke lookup_path(["Bar", "Baz"]) on it, we'll get Foo::Bar::Baz as the return value.

The path is searched in the current type's ancestors, and optionally in its namespace, according to lookup_in_namespace.

Returns nil if the path can't be found.

include_private controls whether private types are found inside other types (when doing Foo::Bar, Bar won't be found if it's private).

location can be passed and is the location where the lookup happens, and is useful to find file-private types.

The result can be an ASTNode in the case the path denotes a type variable whose variable is an ASTNode. One such example is the N of StaticArray(T, N) for some instantiated StaticArray.

If the path is global (for example ::Foo::Bar), the search starts at the top level.


[View source]
def lookup_path(names : Array(String), lookup_in_namespace = true, include_private = false, location = nil) : Type | ASTNode | Nil #

Looks up a path (for example: Foo::Bar::Baz) relative to self.

For example, given:

class Foo
  class Bar
    class Baz
    end
  end
end

If self is Foo and we invoke lookup_path(["Bar", "Baz"]) on it, we'll get Foo::Bar::Baz as the return value.

The path is searched in the current type's ancestors, and optionally in its namespace, according to lookup_in_namespace.

Returns nil if the path can't be found.

include_private controls whether private types are found inside other types (when doing Foo::Bar, Bar won't be found if it's private).

location can be passed and is the location where the lookup happens, and is useful to find file-private types.

The result can be an ASTNode in the case the path denotes a type variable whose variable is an ASTNode. One such example is the N of StaticArray(T, N) for some instantiated StaticArray.

If the path is global (for example ::Foo::Bar), the search starts at the top level.


[View source]
def lookup_path_item(name : String, lookup_self, lookup_in_namespace, include_private, location) : Type | ASTNode | Nil #

Looks up a single path item relative to *self`.

If lookup_in_namespace is true, if the type is not found in self or self's parents, the path item is searched in this type's namespace. This parameter is useful because when writing Foo::Bar::Baz, Foo should be searched in enclosing namespaces, but Bar and Baz not.

If lookup_self is true, if the type is not found under self but has the same name as self, then self is returned. This has higher precedence than ancestors and the enclosing namespace.


[View source]
def lookup_similar_def(name, args_size, block) #

[View source]
def lookup_similar_def_name(name, args_size, block) #

[View source]
def lookup_similar_instance_var_name(ivar_name : String) #

[View source]
def lookup_similar_instance_var_name(name) #

[View source]
def lookup_similar_path(node : Path) #

[View source]
def lookup_similar_path(names : Array(String), lookup_in_namespace = true) #

[View source]
def lookup_type(node : ASTNode, self_type = self.instance_type, allow_typeof = true, free_vars : Hash(String, TypeVar) | Nil = nil, find_root_generic_type_parameters = true) : Type #

Searches the type that corresponds to the given node, relative to self.

This method handles AST nodes in the type grammar:

  • Path: Foo::Bar::Baz
  • Union: T | U
  • Metaclass: T.class
  • Generic: Foo(T)
  • ProcNotation: T -> U
  • TypeOf: typeof(...)
  • Self: self

Passing other AST nodes will raise an exception.

self_type is the type that will be used when self is encountered in the node.

If allow_typeof is false, this method raises if there's a typeof in the given node.

If free_vars is given, when resolving a Path, types will be first searched in the given Hash.

If find_root_generic_type_parameters is true (the default), type parameters relative to self_type will be found. If false, they won't be found.

For example, given:

class Foo
  class Bar(T)
  end

  class Baz
  end
end

If self is Foo and Bar(Baz) is given, the result will be Foo::Bar(Baz).


[View source]
def lookup_type?(node : ASTNode, self_type = self.instance_type, allow_typeof = true, free_vars : Hash(String, TypeVar) | Nil = nil, find_root_generic_type_parameters = true) : Type | Nil #

Similar to #lookup_type, but returns nil if a type can't be found.


[View source]
def lookup_type_var(node : Path, free_vars : Hash(String, TypeVar) | Nil = nil, find_root_generic_type_parameters = true, remove_alias = true) : Type | ASTNode #

Similar to #lookup_type, but the result might also be an ASTNode, for example when looking N relative to a StaticArray.


[View source]
def lookup_type_var?(node : Path, free_vars : Hash(String, TypeVar) | Nil = nil, raise = false, find_root_generic_type_parameters = true) : Type | ASTNode | Nil #

Similar to #lookup_type_var, but might return nil.


[View source]
def macros : Hash(String, Array(Macro)) | Nil #

Returns all macros defines in this type, indexed by their name. This does not include methods defined in ancestors.


[View source]
def metaclass : Type #

Returns this type's metaclass, which holds class methods for this type.


[View source]
def metaclass? #

[View source]
def module? #

[View source]
def namespace : ModuleType #

The namespace this type belongs to. Every type belongs to a namespace, and, when not explicit, the namespace is the Program itself.


[View source]
def nil_type? #

[View source]
def nilable? #

[View source]
def no_return? #

[View source]
def opaque_id #

An opaque id of every type. 0 for Nil, non zero for others, so we can sort types by opaque_id and have Nil in the beginning.


[View source]
def packed? #

Returns true if this type has the @[Packed] annotation on it (only applicable for C structs)


[View source]
def parents #

[View source]
def passed_as_self? #

Returns true if this type is passed as a self argument in the codegen phase. For example a method whose receiver is the Program, or a non-generic metaclass, doesn't have a self argument.


[View source]
def passed_by_value? #

Returns true if this type passed by value (if it's not a primitive type). In the codegen phase these types are passed as byval pointers.


[View source]
def pointer? #

[View source]
def pretty_print(pp) #

[View source]
def private=(set_private) #

[View source]
def private? #

[View source]
def proc? #

[View source]
def program : Crystal::Program #

Returns the program where this type belongs.


[View source]
def reference_like? #

Returns true if this type inherits from Reference or if this is a union type where all types are reference types or nil. In this case this type can be represented with a single pointer.


[View source]
def remove_alias #

[View source]
def remove_alias_if_simple #

[View source]
def remove_indirection #

[View source]
def remove_literal #

[View source]
def remove_typedef #

[View source]
def replace_type_parameters(instance) : Type #

Replace type parameters in this type with the type parameters of the given instance type.


[View source]
def restrict(other : Nil, context) #

[View source]
def restrict(other : AliasType, context) #

[View source]
def restrict(other : UnionType, context) #

[View source]
def restrict(other : VirtualType, context) #

[View source]
def restrict(other : GenericClassType, context) #

[View source]
def restrict(other : Type, context) #

[View source]
def restrict(other : Self, context) #

[View source]
def restrict(other : TypeOf, context) #

[View source]
def restrict(other : Union, context) #

[View source]
def restrict(other : Path, context) #

[View source]
def restrict(other : Generic, context) #

[View source]
def restrict(other : Metaclass, context) #

[View source]
def restrict(other : ProcNotation, context) #

[View source]
def restrict(other : Underscore, context) #

[View source]
def restrict(other : Arg, context) #

[View source]
def restrict(other : NumberLiteral, context) #

[View source]
def restrict(other : Splat, context) #

[View source]
def restrict(other : ASTNode, context) #

[View source]
def restriction_of?(other : UnionType, owner, self_free_vars = nil, other_free_vars = nil) #

[View source]
def restriction_of?(other : VirtualType, owner, self_free_vars = nil, other_free_vars = nil) #

[View source]
def restriction_of?(other : AliasType, owner, self_free_vars = nil, other_free_vars = nil) #

[View source]
def restriction_of?(other : Type, owner, self_free_vars = nil, other_free_vars = nil) #

[View source]
def restriction_of?(other : ASTNode, owner, self_free_vars = nil, other_free_vars = nil) #

[View source]
def same_namespace?(other) #

Returns true if self and other are in the same namespace.


[View source]
def sizeof_type #

Returns the type that has to be used in sizeof and instance_sizeof computations


[View source]
def splat_index #

[View source]
def struct? #

Returns true if this type is a struct.


[View source]
def subclasses : Array(Type) #

Returns direct subclasses of this type.


[View source]
def superclass : Type | Nil #

Returns this type's superclass, or nil if it doesn't have one


[View source]
def to_s(io : IO) : Nil #
Description copied from class Reference

Appends a short String representation of this object which includes its class name and its object address.

class Person
  def initialize(@name : String, @age : Int32)
  end
end

Person.new("John", 32).to_s # => #<Person:0x10a199f20>

[View source]
def to_s(*, generic_args : Bool = true) #

[View source]
abstract def to_s_with_options(io : IO, skip_union_parens : Bool = false, generic_args : Bool = true, codegen : Bool = false) : Nil #

[View source]
def type_desc #

[View source]
def type_var?(name) #

Returns true if name if an unbound type variable in this (generic) type.


[View source]
def type_vars #

[View source]
def types #

[View source]
def types? #

[View source]
def unbound? #

[View source]
def virtual? #

[View source]
def virtual_metaclass? #

[View source]
def virtual_type #

[View source]
def virtual_type! #

[View source]
def void? #

[View source]