Skip to content

Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

Range#to_a

to_a → array

Returns an array containing the elements in self, if a finite collection; raises an exception otherwise.

Example
(1..4).to_a     # => [1, 2, 3, 4]
(1...4).to_a    # => [1, 2, 3]
('a'..'d').to_a # => ["a", "b", "c", "d"]
See also #step #to_json #size #to_s also in 4.1 · 4.0 · 3.4 · 3.2 · 3.1 · 3.0