summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
authortmm1 <tmm1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-01-06 19:38:20 (GMT)
committertmm1 <tmm1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-01-06 19:38:20 (GMT)
commit3cf4fe47e80548011c5c136c7447f24b587c40e6 (patch)
treeeddb9de7ba3b97653075caf38365dbd355b732b7 /array.c
parent7dfbcc85d2e31fcb9af50c66486e82e1bc4dc2df (diff)
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
Diffstat (limited to 'array.c')
-rw-r--r--array.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/array.c b/array.c
index c486978..775fb24 100644
--- a/array.c
+++ b/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;
}