summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-04-14 08:57:23 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-04-14 08:57:23 +0000
commit125d830eb8525151861e932f4a01e76ac5c8b25e (patch)
tree74f570eb217648b78bdf3a83160548d8139652e0
parent39df01c4af5fa7e4246f2a951e4fcc73a3a6aee0 (diff)
* array.c (rb_ary_collect_bang, rb_ary_select): Return an
enumerator if no block is given. * dir.c (dir_each, dir_foreach): Return an enumerator if no block is given. * enum.c (enum_partition, enum_sort_by): Ditto. * gc.c (os_each_obj): Ditto. * hash.c (rb_hash_delete_if, rb_hash_reject_bang, rb_hash_select, rb_hash_each_value, rb_hash_each_key, rb_hash_each_pair, env_each_key, env_each_value, env_each, env_each_pair, env_reject_bang, env_delete_if, env_select): Ditto. * numeric.c (num_step, int_upto, int_downto, int_dotimes): Ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@16008 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog19
-rw-r--r--NEWS57
-rw-r--r--array.c2
-rw-r--r--dir.c2
-rw-r--r--enum.c7
-rw-r--r--gc.c9
-rw-r--r--hash.c26
-rw-r--r--numeric.c8
8 files changed, 117 insertions, 13 deletions
diff --git a/ChangeLog b/ChangeLog
index 5b1a753..1686652 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+Mon Apr 14 17:55:30 2008 Akinori MUSHA <knu@iDaemons.org>
+
+ * array.c (rb_ary_collect_bang, rb_ary_select): Return an
+ enumerator if no block is given.
+
+ * dir.c (dir_each, dir_foreach): Return an enumerator if no block
+ is given.
+
+ * enum.c (enum_partition, enum_sort_by): Ditto.
+
+ * gc.c (os_each_obj): Ditto.
+
+ * hash.c (rb_hash_delete_if, rb_hash_reject_bang, rb_hash_select,
+ rb_hash_each_value, rb_hash_each_key, rb_hash_each_pair,
+ env_each_key, env_each_value, env_each, env_each_pair,
+ env_reject_bang, env_delete_if, env_select): Ditto.
+
+ * numeric.c (num_step, int_upto, int_downto, int_dotimes): Ditto.
+
Mon Apr 14 16:42:53 2008 Akinori MUSHA <knu@iDaemons.org>
* ruby.h (rb_block_call_func): Fix prototype.
diff --git a/NEWS b/NEWS
index aeb1bcd..e92ec21 100644
--- a/NEWS
+++ b/NEWS
@@ -26,6 +26,8 @@ with all sufficient information, see the ChangeLog file.
Take a block instead of an argument.
+ * Array#collect!
+ * Array#map!
* Array#each
* Array#each_index
* Array#reverse_each
@@ -41,6 +43,11 @@ with all sufficient information, see the ChangeLog file.
Take an optional argument specifying the number of elements to
remove.
+ * Dir#each
+ * Dir#foreach
+
+ Return an enumerator if no block is given.
+
* Enumerable::Enumerator
New class for various enumeration defined by the enumerator library.
@@ -54,20 +61,60 @@ with all sufficient information, see the ChangeLog file.
New methods for various enumeration defined by the enumerator library.
- * Enumerator#count
+ * Enumerable#count
* Enumerable#find_index
* Enumerable#first
* Enumerable#group_by
New methods.
- * Integer#ord implemented.
- * Integer#odd? implemented.
- * Integer#even? implemented.
- * Integer#pred implemented.
+ * Enumerable#find_all
+ * Enumerable#partition
+ * Enumerable#select
+ * Enumerable#sort_by
+
+ Return an enumerator if no block is given.
+
+ * Hash#delete_if
+ * Hash#each
+ * Hash#each_key
+ * Hash#each_pair
+ * Hash#each_value
+ * Hash#reject!
+ * Hash#select
+ * ENV.delete_if
+ * ENV.each
+ * ENV.each_key
+ * ENV.each_pair
+ * ENV.each_value
+ * ENV.reject!
+ * ENV.select
+
+ Return an enumerator if no block is given.
+
+ * Integer#ord
+ * Integer#odd?
+ * Integer#even?
+ * Integer#pred
+
+ New methods.
+
+ * Integer#downto
+ * Integer#times
+ * Integer#upto
+
+ Return an enumerator if no block is given.
+
+ * Numeric#step
+
+ Return an enumerator if no block is given.
* Object#tap implemented.
+ * ObjectSpace.each_object
+
+ Return an enumerator if no block is given.
+
* Process.exec implemented.
* Range#each
diff --git a/array.c b/array.c
index 37bc123..f798c4e 100644
--- a/array.c
+++ b/array.c
@@ -1853,6 +1853,7 @@ rb_ary_collect_bang(ary)
{
long i;
+ RETURN_ENUMERATOR(ary, 0, 0);
rb_ary_modify(ary);
for (i = 0; i < RARRAY(ary)->len; i++) {
rb_ary_store(ary, i, rb_yield(RARRAY(ary)->ptr[i]));
@@ -1937,6 +1938,7 @@ rb_ary_select(ary)
VALUE result;
long i;
+ RETURN_ENUMERATOR(ary, 0, 0);
result = rb_ary_new2(RARRAY(ary)->len);
for (i = 0; i < RARRAY(ary)->len; i++) {
if (RTEST(rb_yield(RARRAY(ary)->ptr[i]))) {
diff --git a/dir.c b/dir.c
index b6e1976..118d2ff 100644
--- a/dir.c
+++ b/dir.c
@@ -562,6 +562,7 @@ dir_each(dir)
struct dir_data *dirp;
struct dirent *dp;
+ RETURN_ENUMERATOR(dir, 0, 0);
GetDIR(dir, dirp);
rewinddir(dirp->dir);
for (dp = readdir(dirp->dir); dp != NULL; dp = readdir(dirp->dir)) {
@@ -1814,6 +1815,7 @@ dir_foreach(io, dirname)
{
VALUE dir;
+ RETURN_ENUMERATOR(io, 1, &dirname);
dir = dir_open_dir(dirname);
rb_ensure(dir_each, dir, dir_close, dir);
return Qnil;
diff --git a/enum.c b/enum.c
index d77d631..353e8dd 100644
--- a/enum.c
+++ b/enum.c
@@ -330,7 +330,8 @@ enum_find_all(obj)
VALUE obj;
{
VALUE ary = rb_ary_new();
-
+
+ RETURN_ENUMERATOR(obj, 0, 0);
rb_iterate(rb_each, obj, find_all_i, ary);
return ary;
@@ -521,6 +522,8 @@ enum_partition(obj)
{
VALUE ary[2];
+ RETURN_ENUMERATOR(obj, 0, 0);
+
ary[0] = rb_ary_new();
ary[1] = rb_ary_new();
rb_iterate(rb_each, obj, partition_i, (VALUE)ary);
@@ -759,6 +762,8 @@ enum_sort_by(obj)
VALUE ary;
long i;
+ RETURN_ENUMERATOR(obj, 0, 0);
+
if (TYPE(obj) == T_ARRAY) {
ary = rb_ary_new2(RARRAY(obj)->len);
}
diff --git a/gc.c b/gc.c
index ed22425..401c0fa 100644
--- a/gc.c
+++ b/gc.c
@@ -1669,16 +1669,21 @@ os_obj_of(of)
*/
static VALUE
-os_each_obj(argc, argv)
+os_each_obj(argc, argv, os)
int argc;
VALUE *argv;
+ VALUE os;
{
VALUE of;
rb_secure(4);
- if (rb_scan_args(argc, argv, "01", &of) == 0) {
+ if (argc == 0) {
of = 0;
}
+ else {
+ rb_scan_args(argc, argv, "01", &of);
+ }
+ RETURN_ENUMERATOR(os, 1, &of);
return os_obj_of(of);
}
diff --git a/hash.c b/hash.c
index 290a253..863c989 100644
--- a/hash.c
+++ b/hash.c
@@ -817,6 +817,7 @@ VALUE
rb_hash_delete_if(hash)
VALUE hash;
{
+ RETURN_ENUMERATOR(hash, 0, 0);
rb_hash_modify(hash);
rb_hash_foreach(hash, delete_if_i, hash);
return hash;
@@ -834,7 +835,10 @@ VALUE
rb_hash_reject_bang(hash)
VALUE hash;
{
- int n = RHASH(hash)->tbl->num_entries;
+ int n;
+
+ RETURN_ENUMERATOR(hash, 0, 0);
+ n = RHASH(hash)->tbl->num_entries;
rb_hash_delete_if(hash);
if (n == RHASH(hash)->tbl->num_entries) return Qnil;
return hash;
@@ -912,6 +916,7 @@ rb_hash_select(hash)
{
VALUE result;
+ RETURN_ENUMERATOR(hash, 0, 0);
result = rb_ary_new();
rb_hash_foreach(hash, select_i, result);
return result;
@@ -1090,6 +1095,7 @@ static VALUE
rb_hash_each_value(hash)
VALUE hash;
{
+ RETURN_ENUMERATOR(hash, 0, 0);
rb_hash_foreach(hash, each_value_i, 0);
return hash;
}
@@ -1122,6 +1128,7 @@ static VALUE
rb_hash_each_key(hash)
VALUE hash;
{
+ RETURN_ENUMERATOR(hash, 0, 0);
rb_hash_foreach(hash, each_key_i, 0);
return hash;
}
@@ -1156,6 +1163,7 @@ static VALUE
rb_hash_each_pair(hash)
VALUE hash;
{
+ RETURN_ENUMERATOR(hash, 0, 0);
rb_hash_foreach(hash, each_pair_i, 0);
return hash;
}
@@ -2003,6 +2011,7 @@ env_each_key(ehash)
VALUE keys = env_keys();
long i;
+ RETURN_ENUMERATOR(ehash, 0, 0);
for (i=0; i<RARRAY(keys)->len; i++) {
rb_yield(RARRAY(keys)->ptr[i]);
}
@@ -2034,6 +2043,7 @@ env_each_value(ehash)
VALUE values = env_values();
long i;
+ RETURN_ENUMERATOR(ehash, 0, 0);
for (i=0; i<RARRAY(values)->len; i++) {
rb_yield(RARRAY(values)->ptr[i]);
}
@@ -2075,6 +2085,7 @@ static VALUE
env_each(ehash)
VALUE ehash;
{
+ RETURN_ENUMERATOR(ehash, 0, 0);
return env_each_i(ehash, Qfalse);
}
@@ -2086,12 +2097,14 @@ env_each_pair(ehash)
}
static VALUE
-env_reject_bang()
+env_reject_bang(ehash)
+ VALUE ehash;
{
volatile VALUE keys;
long i;
int del = 0;
+ RETURN_ENUMERATOR(ehash, 0, 0);
rb_secure(4);
keys = env_keys();
@@ -2110,9 +2123,10 @@ env_reject_bang()
}
static VALUE
-env_delete_if()
+env_delete_if(ehash)
+ VALUE ehash;
{
- env_reject_bang();
+ env_reject_bang(ehash);
return envtbl;
}
@@ -2131,11 +2145,13 @@ env_values_at(argc, argv)
}
static VALUE
-env_select()
+env_select(ehash)
+ VALUE ehash;
{
VALUE result;
char **env;
+ RETURN_ENUMERATOR(ehash, 0, 0);
result = rb_ary_new();
env = GET_ENVIRON(environ);
while (*env) {
diff --git a/numeric.c b/numeric.c
index 7abc605..c6ef250 100644
--- a/numeric.c
+++ b/numeric.c
@@ -1463,6 +1463,8 @@ num_step(argc, argv, from)
{
VALUE to, step;
+ RETURN_ENUMERATOR(from, argc, argv);
+
if (argc == 1) {
to = argv[0];
step = INT2FIX(1);
@@ -2845,6 +2847,8 @@ static VALUE
int_upto(from, to)
VALUE from, to;
{
+ RETURN_ENUMERATOR(from, 1, &to);
+
if (FIXNUM_P(from) && FIXNUM_P(to)) {
long i, end;
@@ -2884,6 +2888,8 @@ static VALUE
int_downto(from, to)
VALUE from, to;
{
+ RETURN_ENUMERATOR(from, 1, &to);
+
if (FIXNUM_P(from) && FIXNUM_P(to)) {
long i, end;
@@ -2924,6 +2930,8 @@ static VALUE
int_dotimes(num)
VALUE num;
{
+ RETURN_ENUMERATOR(num, 0, 0);
+
if (FIXNUM_P(num)) {
long i, end;