While reading through the Crystal docs, I came across this line:
deq = Deque{2, 3}
So I think this calls the Deque.new(array : Array(T))
constructor. However, I did not find any documentation about this syntax whatsoever.
(EDIT: The documentation can be found here)
To test this way of calling constructors, I wrote the following test
class Foo(T)
def initialize(@bar : Array(T)); end
def to_s(io : IO)
io << "Foo: "
io << @bar
end
end
puts Foo{1} # Line 10
But, compiling it prints this error:
Error in line 10: wrong number of arguments for 'Foo(Int32).new' (given 0, expected 1)
Overloads are:
- Foo(T).new(bar : Array(T))
Which I really don't understand at all.
Foo(Int32){1}
Raises the same error.
Question is, what is this Klass{1, 2, 3}
syntax? And how do you use it?