Method: Array#thru
- Defined in:
- lib/core/facets/array/from.rb
#thru(from, to = nil) ⇒ Object
Fetch values from a start index thru an end index.
[1,2,3,4,5].thru(0,2) #=> [1,2,3]
[1,2,3,4,5].thru(2,4) #=> [3,4,5]
[1,2,3,4,5].thru(2) #=> [1,2,3]
[1,2,3,4,5].thru(4) #=> [1,2,3,4,5]
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/core/facets/array/from.rb', line 20 def thru(from, to=nil) from, to = 0, from unless to to = size - 1 if to >= size a = [] i = from while i <= to a << self[i] i += 1 end a end |