所以我刚开始学习Crystal,因为我喜欢Ruby和C,但我还是无法掌握语法.我想我很亲密,但我坚持这个错误.
no overload matches 'Array(Person)#+' with type Person
Overloads are:
- Array(T)#+(other : Array(U))
people += Person.new("Person#{id}")
这是代码.
class Person
def initialize(name : String)
@name = name
@age = 0
end
def name
@name
end
def age
@age
end
end
people = [] of Person
counter = 0
id = 0
loop do
id+=1
people += Person.new("Person#{id}")
counter+=1
break if counter = 5
end
puts(people)
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?提前致谢!