W3cubDocs

/Crystal

is_a?

The pseudo-method is_a? determines whether an expression's runtime type inherits or includes another type. For example:

a = 1
a.is_a?(Int32)          # => true
a.is_a?(String)         # => false
a.is_a?(Number)         # => true
a.is_a?(Int32 | String) # => true

It is a pseudo-method because the compiler knows about it and it can affect type information, as explained in if var.is_a?(...). Also, it accepts a type that must be known at compile-time as its argument.

To the extent possible under law, the persons who contributed to this workhave waived
all copyright and related or neighboring rights to this workby associating CC0 with it.
https://crystal-lang.org/docs/syntax_and_semantics/is_a.html