10

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?

Johan Svensson
  • 315
  • 2
  • 11

1 Answers1

4

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, [...]]]]]
Torsten Robitzki
  • 3,041
  • 1
  • 21
  • 35