mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Added Array#prepend as an alias for Array#unshift and Array#append as an alias for Array#<< [DHH]
This commit is contained in:
parent
bb4e790dff
commit
9482554f31
4 changed files with 20 additions and 0 deletions
|
@ -1,5 +1,7 @@
|
|||
*Rails 3.2.0 (unreleased)*
|
||||
|
||||
* Added Array#prepend as an alias for Array#unshift and Array#append as an alias for Array#<< [DHH]
|
||||
|
||||
* Removed support for using Module#delegate to delegate to non-public methods [Jon Leighton]
|
||||
|
||||
* The definition of blank string for Ruby 1.9 has been extended to Unicode whitespace.
|
||||
|
|
|
@ -5,3 +5,4 @@ require 'active_support/core_ext/array/conversions'
|
|||
require 'active_support/core_ext/array/extract_options'
|
||||
require 'active_support/core_ext/array/grouping'
|
||||
require 'active_support/core_ext/array/random_access'
|
||||
require 'active_support/core_ext/array/prepend_and_append'
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
class Array
|
||||
# The human way of thinking about adding stuff to the end of a list is with append
|
||||
alias_method :append, :<<
|
||||
|
||||
# The human way of thinking about adding stuff to the beginning of a list is with prepend
|
||||
alias_method :prepend, :unshift
|
||||
end
|
|
@ -465,3 +465,13 @@ class ArrayWrapperTests < Test::Unit::TestCase
|
|||
assert_equal DoubtfulToAry.new.to_ary, Array.wrap(DoubtfulToAry.new)
|
||||
end
|
||||
end
|
||||
|
||||
class ArrayPrependAppendTest < Test::Unit::TestCase
|
||||
def test_append
|
||||
assert_equal [1, 2], [1].append(2)
|
||||
end
|
||||
|
||||
def test_prepend
|
||||
assert_equal [2, 1], [1].prepend(2)
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue