From 0e9401733c55e3ca43e48ad2b9b60520ef57387f Mon Sep 17 00:00:00 2001 From: Kuldeep Aggarwal Date: Fri, 23 May 2014 21:32:52 +0530 Subject: revert 96525d63 `Array#to` is working for negative position --- activesupport/lib/active_support/core_ext/array/access.rb | 4 +++- activesupport/test/core_ext/array_ext_test.rb | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/core_ext/array/access.rb b/activesupport/lib/active_support/core_ext/array/access.rb index 67f58bc0fe..3f65f97524 100644 --- a/activesupport/lib/active_support/core_ext/array/access.rb +++ b/activesupport/lib/active_support/core_ext/array/access.rb @@ -15,8 +15,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 self[1]. diff --git a/activesupport/test/core_ext/array_ext_test.rb b/activesupport/test/core_ext/array_ext_test.rb index e0e54f47e4..789a490831 100644 --- a/activesupport/test/core_ext/array_ext_test.rb +++ b/activesupport/test/core_ext/array_ext_test.rb @@ -16,6 +16,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 -- cgit v1.2.3