What is [....] in Ruby?

object, ruby

Solution

It's just the way Array.inspect displays recursive arrays. The last Element of a is a itself. If a where displayed after 5, inspect would end up in an endless loop:

[1, 2, 3, 4, 5, [1, 2, 3, 4, 5, [1, 2, 3, 4, 5, [1, 2, 3, 4, 5, [...]]]]]

Problem

I ended up accidentally doing the equivalent of this in Ruby the other night: ``` a = *1..5 # => [1, 2, 3, 4, 5] a << a a # => [1, 2, 3, 4, 5, [...]] a.last # => [1, 2, 3, 4, 5, [...]] ``` What is `[...]` and what can I do with it?

Original source

Related problems