diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-05-23 15:05:28 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-05-23 15:05:28 -0300 |
commit | a31277011814b7bdb6be41a807e14d6bf2852620 (patch) | |
tree | 3a93279c7d1b2cc2b9568a9cdb960d294eef5c66 /activesupport | |
parent | cb7f03f061264ae1d4626369bf7f1264d0914a2b (diff) | |
parent | 0e9401733c55e3ca43e48ad2b9b60520ef57387f (diff) | |
download | rails-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')
-rw-r--r-- | activesupport/lib/active_support/core_ext/array/access.rb | 4 | ||||
-rw-r--r-- | activesupport/test/core_ext/array_ext_test.rb | 2 |
2 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 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>. diff --git a/activesupport/test/core_ext/array_ext_test.rb b/activesupport/test/core_ext/array_ext_test.rb index 4601a80d42..bd1b818717 100644 --- a/activesupport/test/core_ext/array_ext_test.rb +++ b/activesupport/test/core_ext/array_ext_test.rb @@ -18,6 +18,8 @@ class ArrayExtAccessTests < ActiveSupport::TestCase assert_equal %w( a ), %w( a b c d ).to(0) assert_equal %w( a b c ), %w( a b c d ).to(2) assert_equal %w( a b c d ), %w( a b c d ).to(10) + assert_equal %w( a b c ), %w( a b c d ).to(-2) + assert_equal %w(), %w( a b c ).to(-10) end def test_second_through_tenth |