diff options
author | Akira Matsuda <ronnie@dio.jp> | 2014-10-07 19:52:12 +0900 |
---|---|---|
committer | Akira Matsuda <ronnie@dio.jp> | 2014-10-25 12:59:37 +0900 |
commit | ed03d4eaa89a7b4ab09e7f5da76b522d04650daf (patch) | |
tree | 715b7baead96212c46ded13346436a7d71de3523 /activesupport/lib | |
parent | 88080e262928f8b3fc8eb0241a09ea5b3c559725 (diff) | |
download | rails-ed03d4eaa89a7b4ab09e7f5da76b522d04650daf.tar.gz rails-ed03d4eaa89a7b4ab09e7f5da76b522d04650daf.tar.bz2 rails-ed03d4eaa89a7b4ab09e7f5da76b522d04650daf.zip |
Avoid creating range objects (take II)
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/core_ext/array/access.rb | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/core_ext/array/access.rb b/activesupport/lib/active_support/core_ext/array/access.rb index caa499dfa2..45b89d2705 100644 --- a/activesupport/lib/active_support/core_ext/array/access.rb +++ b/activesupport/lib/active_support/core_ext/array/access.rb @@ -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>. |