mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
1.4.0
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@520 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
fcd020c830
commit
65a5162550
156 changed files with 21888 additions and 18301 deletions
28
enum.c
28
enum.c
|
@ -6,7 +6,7 @@
|
|||
$Date$
|
||||
created at: Fri Oct 1 15:15:19 JST 1993
|
||||
|
||||
Copyright (C) 1993-1998 Yukihiro Matsumoto
|
||||
Copyright (C) 1993-1999 Yukihiro Matsumoto
|
||||
|
||||
************************************************/
|
||||
|
||||
|
@ -56,6 +56,7 @@ enum_grep(obj, pat)
|
|||
arg[0] = pat; arg[1] = tmp = rb_ary_new();
|
||||
rb_iterate(rb_each, obj, grep_i, (VALUE)arg);
|
||||
|
||||
if (RARRAY(tmp)->len == 0) return Qnil;
|
||||
return tmp;
|
||||
}
|
||||
}
|
||||
|
@ -121,6 +122,28 @@ enum_find_all(obj)
|
|||
return tmp;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
reject_i(i, tmp)
|
||||
VALUE i, tmp;
|
||||
{
|
||||
if (!RTEST(rb_yield(i))) {
|
||||
rb_ary_push(tmp, i);
|
||||
}
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
enum_reject(obj)
|
||||
VALUE obj;
|
||||
{
|
||||
VALUE tmp;
|
||||
|
||||
tmp = rb_ary_new();
|
||||
rb_iterate(rb_each, obj, reject_i, tmp);
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
collect_i(i, tmp)
|
||||
VALUE i, tmp;
|
||||
|
@ -373,7 +396,10 @@ Init_Enumerable()
|
|||
rb_define_method(rb_mEnumerable,"sort", enum_sort, 0);
|
||||
rb_define_method(rb_mEnumerable,"grep", enum_grep, 1);
|
||||
rb_define_method(rb_mEnumerable,"find", enum_find, -1);
|
||||
rb_define_method(rb_mEnumerable,"detect", enum_find, -1);
|
||||
rb_define_method(rb_mEnumerable,"find_all", enum_find_all, 0);
|
||||
rb_define_method(rb_mEnumerable,"select", enum_find_all, 0);
|
||||
rb_define_method(rb_mEnumerable,"reject", enum_reject, 0);
|
||||
rb_define_method(rb_mEnumerable,"collect", enum_collect, 0);
|
||||
rb_define_method(rb_mEnumerable,"min", enum_min, 0);
|
||||
rb_define_method(rb_mEnumerable,"max", enum_max, 0);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue