Search code examples
crystal-lang

Can variable type in Crystal lang be restricted to classes that inherit from one class


I mean:

class Foo; end
class Bar < Foo; end
class Cux < Foo; end

Is it possible to restrict type of the variable to classes inheriting from Foo without unions, something like x : Foo+?


Solution

  • Maybe using a type restriction?

    @x : Foo