Actions
Feature #1153
closedEnumerable#uniq
Feature #1153:
Enumerable#uniq
Description
=begin
なかだです。
Arrayだけでなく、Enumerableにもuniqがあってもいいんじゃないでしょ
うか。
Index: enum.c¶
--- enum.c (revision 22100)
+++ enum.c (working copy)
@@ -1794,4 +1794,29 @@ enum_cycle(int argc, VALUE *argv, VALUE
}
+static VALUE
+enum_uniq_i(VALUE i, VALUE hash, int argc, VALUE *argv)
+{
- return rb_hash_aset(hash, i, Qtrue);
+}
+static int
+push_key(st_data_t key, st_data_t val, st_data_t ary)
+{
- rb_ary_push((VALUE)ary, (VALUE)key);
- return ST_DELETE;
+}
+static VALUE
+enum_uniq(VALUE obj)
+{
- VALUE hash = rb_hash_new(), uniq;
- RBASIC(hash)->klass = 0;
- rb_block_call(obj, id_each, 0, 0, enum_uniq_i, hash);
- uniq = rb_ary_new2(RHASH_SIZE(hash));
- st_foreach(RHASH_TBL(hash), push_key, uniq);
- return uniq;
+}
/*
- The
Enumerable
mixin provides collection classes with
@@ -1853,4 +1878,5 @@ Init_Enumerable(void)
rb_define_method(rb_mEnumerable, "drop_while", enum_drop_while, 0);
rb_define_method(rb_mEnumerable, "cycle", enum_cycle, -1);
-
rb_define_method(rb_mEnumerable, "uniq", enum_uniq, 0);
id_eqq = rb_intern("===");
--
--- 僕の前にBugはない。
--- 僕の後ろにBugはできる。
中田 伸悦
=end
Actions