Skip to content

End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

Range#first

rng.first → obj
rng.first(n) → an_array

Returns the first object in the range, or an array of the first n elements.

Example
(10..20).first     #=> 10
(10..20).first(3)  #=> [10, 11, 12]
See also #exclude_end? #hash #eql? #include? also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1