mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* numeric.c (num_step): better iteration condition for float
values; suggested by Masahiro TANAKA <masa@ir.isas.ac.jp>. * range.c (range_step): step (for Range#step method) <= 0 makes no sence, thus ArgError will be raised. * range.c (range_each): Range#each method is special case for Range#step(1) * file.c (rb_find_file): load must be done from an abolute path if $SAFE >= 4. * enum.c (enum_partition): new method. [new] * re.c (rb_reg_s_quote): quote whitespaces for /x cases. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2420 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
ca55fe4f0d
commit
4fa0cdea78
7 changed files with 155 additions and 104 deletions
27
enum.c
27
enum.c
|
@ -216,6 +216,32 @@ enum_inject(argc, argv, obj)
|
|||
return n;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
partition_i(i, ary)
|
||||
VALUE i, *ary;
|
||||
{
|
||||
if (RTEST(rb_yield(i))) {
|
||||
rb_ary_push(ary[0], i);
|
||||
}
|
||||
else {
|
||||
rb_ary_push(ary[1], i);
|
||||
}
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
enum_partition(obj)
|
||||
VALUE obj;
|
||||
{
|
||||
VALUE ary[2];
|
||||
|
||||
ary[0] = rb_ary_new();
|
||||
ary[1] = rb_ary_new();
|
||||
rb_iterate(rb_each, obj, partition_i, (VALUE)ary);
|
||||
|
||||
return rb_assoc_new(ary[0], ary[1]);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
enum_sort(obj)
|
||||
VALUE obj;
|
||||
|
@ -475,6 +501,7 @@ Init_Enumerable()
|
|||
rb_define_method(rb_mEnumerable,"collect", enum_collect, 0);
|
||||
rb_define_method(rb_mEnumerable,"map", enum_collect, 0);
|
||||
rb_define_method(rb_mEnumerable,"inject", enum_inject, -1);
|
||||
rb_define_method(rb_mEnumerable,"partition", enum_partition, 0);
|
||||
rb_define_method(rb_mEnumerable,"all?", enum_all, 0);
|
||||
rb_define_method(rb_mEnumerable,"any?", enum_any, 0);
|
||||
rb_define_method(rb_mEnumerable,"min", enum_min, 0);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue