mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Merged pull request #317 from jaredonline/master.
Change Array#from to return consistent results
This commit is contained in:
@@ -3,10 +3,10 @@ class Array
|
||||
#
|
||||
# %w( a b c d ).from(0) # => %w( a b c d )
|
||||
# %w( a b c d ).from(2) # => %w( c d )
|
||||
# %w( a b c d ).from(10) # => nil
|
||||
# %w( a b c d ).from(10) # => %w()
|
||||
# %w().from(0) # => %w()
|
||||
def from(position)
|
||||
self[position..-1]
|
||||
position > length ? [] : self[position..-1]
|
||||
end
|
||||
|
||||
# Returns the beginning of the array up to +position+.
|
||||
|
||||
@@ -10,7 +10,7 @@ class ArrayExtAccessTests < Test::Unit::TestCase
|
||||
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_nil %w( a b c d ).from(10)
|
||||
assert_equal %w(), %w( a b c d ).from(10)
|
||||
end
|
||||
|
||||
def test_to
|
||||
|
||||
Reference in New Issue
Block a user