Skip to content

Commit

Permalink
add test cases for negative position in Array#from
Browse files Browse the repository at this point in the history
  • Loading branch information
kuldeepaggarwal committed May 23, 2014
1 parent 0cc7f02 commit 3920d64
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions activesupport/lib/active_support/core_ext/array/access.rb
Expand Up @@ -5,6 +5,8 @@ class Array
# %w( a b c d ).from(2) # => ["c", "d"]
# %w( a b c d ).from(10) # => []
# %w().from(0) # => []
# %w( a b c d ).from(-2) # => ["c", "d"]
# %w( a b c ).from(-10) # => []
def from(position)
self[position, length] || []
end
Expand Down
2 changes: 2 additions & 0 deletions activesupport/test/core_ext/array_ext_test.rb
Expand Up @@ -10,6 +10,8 @@ def test_from
assert_equal %w( a b c d ), %w( a b c d ).from(0)
assert_equal %w( c d ), %w( a b c d ).from(2)
assert_equal %w(), %w( a b c d ).from(10)
assert_equal %w( d e ), %w( a b c d e ).from(-2)
assert_equal %w(), %w( a b c d e ).from(-10)
end

def test_to
Expand Down

0 comments on commit 3920d64

Please sign in to comment.