提交 a3127701 编写于 作者: R Rafael Mendonça França

Merge pull request #15276 from kuldeepaggarwal/fix-array-to

Array#to now accept negative position also.
......@@ -17,8 +17,10 @@ def from(position)
# %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>.
......
......@@ -18,6 +18,8 @@ def test_to
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册