aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-05-23 15:05:28 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-05-23 15:05:28 -0300
commita31277011814b7bdb6be41a807e14d6bf2852620 (patch)
tree3a93279c7d1b2cc2b9568a9cdb960d294eef5c66 /activesupport/lib/active_support/core_ext
parentcb7f03f061264ae1d4626369bf7f1264d0914a2b (diff)
parent0e9401733c55e3ca43e48ad2b9b60520ef57387f (diff)
downloadrails-a31277011814b7bdb6be41a807e14d6bf2852620.tar.gz
rails-a31277011814b7bdb6be41a807e14d6bf2852620.tar.bz2
rails-a31277011814b7bdb6be41a807e14d6bf2852620.zip
Merge pull request #15276 from kuldeepaggarwal/fix-array-to
Array#to now accept negative position also.
Diffstat (limited to 'activesupport/lib/active_support/core_ext')
-rw-r--r--activesupport/lib/active_support/core_ext/array/access.rb4
1 files changed, 3 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 d0791a161f..caa499dfa2 100644
--- a/activesupport/lib/active_support/core_ext/array/access.rb
+++ b/activesupport/lib/active_support/core_ext/array/access.rb
@@ -17,8 +17,10 @@ class Array
# %w( a b c d ).to(2) # => ["a", "b", "c"]
# %w( a b c d ).to(10) # => ["a", "b", "c", "d"]
# %w().to(0) # => []
+ # %w( a b c d ).to(-2) # => ["a", "b", "c"]
+ # %w( a b c ).to(-10) # => []
def to(position)
- first position + 1
+ self[0..position]
end
# Equal to <tt>self[1]</tt>.