mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Fix Enumerable#uniq with non single yield arguments
* enum.c (uniq_func, uniq_iter): need packed value as the unique key. [ruby-core:81734] [Bug #13669] [Fix GH-1658] Author: Kenichi Kamiya <kachick1@gmail.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59128 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
5eec76bc7b
commit
9cacc53d4a
2 changed files with 3 additions and 0 deletions
2
enum.c
2
enum.c
|
@ -3855,6 +3855,7 @@ enum_sum(int argc, VALUE* argv, VALUE obj)
|
|||
static VALUE
|
||||
uniq_func(RB_BLOCK_CALL_FUNC_ARGLIST(i, hash))
|
||||
{
|
||||
ENUM_WANT_SVALUE();
|
||||
rb_hash_add_new_element(hash, i, i);
|
||||
return Qnil;
|
||||
}
|
||||
|
@ -3862,6 +3863,7 @@ uniq_func(RB_BLOCK_CALL_FUNC_ARGLIST(i, hash))
|
|||
static VALUE
|
||||
uniq_iter(RB_BLOCK_CALL_FUNC_ARGLIST(i, hash))
|
||||
{
|
||||
ENUM_WANT_SVALUE();
|
||||
rb_hash_add_new_element(hash, rb_yield_values2(argc, argv), i);
|
||||
return Qnil;
|
||||
}
|
||||
|
|
|
@ -977,5 +977,6 @@ class TestEnumerable < Test::Unit::TestCase
|
|||
assert_equal([[1896, "Athens"], [1900, "Paris"], [1904, "Chicago"], [1908, "Rome"]],
|
||||
olympics.uniq{|k,v| v})
|
||||
assert_equal([1, 2, 3, 4, 5, 10], (1..100).uniq{|x| (x**2) % 10 }.first(6))
|
||||
assert_equal([1, [1, 2]], Foo.new.to_enum.uniq)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue