1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Avoid creating range objects (take II)

This commit is contained in:
Akira Matsuda 2014-10-07 19:52:12 +09:00
parent 88080e2629
commit ed03d4eaa8

View file

@ -20,7 +20,11 @@ class Array
# %w( a b c d ).to(-2) # => ["a", "b", "c"]
# %w( a b c ).to(-10) # => []
def to(position)
self[0..position]
if position >= 0
first position + 1
else
self[0..position]
end
end
# Equal to <tt>self[1]</tt>.