Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
前几天晚上,我不小心在 Ruby 中做了同样的事情:
a = *1..5 # => [1, 2, 3, 4, 5] a << a a # => [1, 2, 3, 4, 5, [...]] a.last # => [1, 2, 3, 4, 5, [...]]
它是[...]什么,我能用它做什么?
[...]
这只是 Array.inspect 显示递归数组的方式。a 的最后一个元素是 a 本身。如果在 5 之后显示 where,inspect 将进入无限循环:
[1, 2, 3, 4, 5, [1, 2, 3, 4, 5, [1, 2, 3, 4, 5, [1, 2, 3, 4, 5, [...]]]]]