mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Added Array#second through Array#tenth as aliases for Array#[1] through Array#[9] [DHH]
This commit is contained in:
parent
7650ff892c
commit
22af62cf48
3 changed files with 61 additions and 0 deletions
|
@ -1,5 +1,7 @@
|
|||
*Edge*
|
||||
|
||||
* Added Array#second through Array#tenth as aliases for Array#[1] through Array#[9] [DHH]
|
||||
|
||||
* Added test/do declaration style testing to ActiveSupport::TestCase [DHH via Jay Fields]
|
||||
|
||||
* Added Object#present? which is equivalent to !Object#blank? [DHH]
|
||||
|
|
|
@ -20,6 +20,51 @@ module ActiveSupport #:nodoc:
|
|||
def to(position)
|
||||
self[0..position]
|
||||
end
|
||||
|
||||
# Equal to self[1]
|
||||
def second
|
||||
self[1]
|
||||
end
|
||||
|
||||
# Equal to self[2]
|
||||
def third
|
||||
self[2]
|
||||
end
|
||||
|
||||
# Equal to self[3]
|
||||
def fourth
|
||||
self[3]
|
||||
end
|
||||
|
||||
# Equal to self[4]
|
||||
def fifth
|
||||
self[4]
|
||||
end
|
||||
|
||||
# Equal to self[5]
|
||||
def sixth
|
||||
self[5]
|
||||
end
|
||||
|
||||
# Equal to self[6]
|
||||
def seventh
|
||||
self[6]
|
||||
end
|
||||
|
||||
# Equal to self[7]
|
||||
def eighth
|
||||
self[7]
|
||||
end
|
||||
|
||||
# Equal to self[8]
|
||||
def ninth
|
||||
self[8]
|
||||
end
|
||||
|
||||
# Equal to self[9]
|
||||
def tenth
|
||||
self[9]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -13,6 +13,20 @@ class ArrayExtAccessTests < Test::Unit::TestCase
|
|||
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)
|
||||
end
|
||||
|
||||
def test_second_through_tenth
|
||||
array = (1..10).to_a
|
||||
|
||||
assert_equal array[1], array.second
|
||||
assert_equal array[2], array.third
|
||||
assert_equal array[3], array.fourth
|
||||
assert_equal array[4], array.fifth
|
||||
assert_equal array[5], array.sixth
|
||||
assert_equal array[6], array.seventh
|
||||
assert_equal array[7], array.eighth
|
||||
assert_equal array[8], array.ninth
|
||||
assert_equal array[9], array.tenth
|
||||
end
|
||||
end
|
||||
|
||||
class ArrayExtToParamTests < Test::Unit::TestCase
|
||||
|
|
Loading…
Reference in a new issue