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:
parent
88080e2629
commit
ed03d4eaa8
1 changed files with 5 additions and 1 deletions
|
@ -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>.
|
||||
|
|
Loading…
Reference in a new issue