Skip to content
Browse files

fixing Array#from to return consistent results

  • Loading branch information...
1 parent 4ce14fb commit 74634d452b3087575fe7b912da9827021aed4a70 @jaredonline jaredonline committed Apr 26, 2011
View
4 activesupport/lib/active_support/core_ext/array/access.rb
@@ -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+.
View
2 activesupport/test/core_ext/array_ext_test.rb
@@ -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

1 comment on commit 74634d4

@smartinez87

Please don't forget to update the guides with changes like this.
In this case guides have been already updated here: rails/docrails@089ee31

Thanks!

Please sign in to comment.
Something went wrong with that request. Please try again.