mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
array.c: return first unique element in Array#uniq
* array.c (ary_add_hash): Fix consistency issue between Array#uniq and Array#uniq! [Bug #9340] [ruby-core:59457] * test/ruby/test_array.rb (class TestArray): regression test for above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44512 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
7dfbcc85d2
commit
3cf4fe47e8
3 changed files with 14 additions and 1 deletions
|
@ -1,3 +1,9 @@
|
|||
Tue Jan 7 04:35:46 2014 Aman Gupta <ruby@tmm1.net>
|
||||
|
||||
* array.c (ary_add_hash): Fix consistency issue between Array#uniq and
|
||||
Array#uniq! [Bug #9340] [ruby-core:59457]
|
||||
* test/ruby/test_array.rb (class TestArray): regression test for above.
|
||||
|
||||
Mon Jan 6 21:28:48 2014 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
|
||||
|
||||
* .gitignore: ignore *-fake.rb generated even when CROSS_COMPILING = no
|
||||
|
|
4
array.c
4
array.c
|
@ -3908,7 +3908,9 @@ ary_add_hash(VALUE hash, VALUE ary)
|
|||
|
||||
for (i=0; i<RARRAY_LEN(ary); i++) {
|
||||
VALUE elt = RARRAY_AREF(ary, i);
|
||||
rb_hash_aset(hash, elt, elt);
|
||||
if (rb_hash_lookup2(hash, elt, Qundef) == Qundef) {
|
||||
rb_hash_aset(hash, elt, elt);
|
||||
}
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
|
|
@ -1524,6 +1524,11 @@ class TestArray < Test::Unit::TestCase
|
|||
assert(a.none?(&:frozen?))
|
||||
assert_equal(%w(a), b)
|
||||
assert(b.none?(&:frozen?))
|
||||
|
||||
bug9340 = "[ruby-core:59457]"
|
||||
ary = [bug9340, bug9340.dup, bug9340.dup]
|
||||
assert_equal 1, ary.uniq.size
|
||||
assert_same bug9340, ary.uniq[0]
|
||||
end
|
||||
|
||||
def test_uniq_with_block
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue