summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-10-17 14:09:43 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-10-17 14:09:43 +0000
commitc58f1a32e64f7bac0c8f3e70cd2ddfed4118c9e4 (patch)
tree15669c34dd56e1950250456735eaa35d7cd4b5a3
parentc620676e7b0838d4a8a07fdfd6e955c98676cdad (diff)
downloadruby-c58f1a32e64f7bac0c8f3e70cd2ddfed4118c9e4.tar.gz
ruby-c58f1a32e64f7bac0c8f3e70cd2ddfed4118c9e4.tar.xz
ruby-c58f1a32e64f7bac0c8f3e70cd2ddfed4118c9e4.zip
* ext/enumerator/enumerator.c, ext/enumerator/enumerator.txt:
Provide Kernel#to_enum as an alias for Kernel#enum_for. Maybe this is a better name. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@4798 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--ext/enumerator/enumerator.c5
-rw-r--r--ext/enumerator/enumerator.txt5
3 files changed, 14 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 723c7323e..83f9681aa 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Fri Oct 17 23:07:38 2003 Akinori MUSHA <knu@iDaemons.org>
+
+ * ext/enumerator/enumerator.c, ext/enumerator/enumerator.txt:
+ Provide Kernel#to_enum as an alias for Kernel#enum_for. Maybe
+ this is a better name.
+
Fri Oct 17 23:00:30 2003 Akinori MUSHA <knu@iDaemons.org>
* lib/generator.rb: Add rdoc documentation.
diff --git a/ext/enumerator/enumerator.c b/ext/enumerator/enumerator.c
index a4a0222fb..8c3c56617 100644
--- a/ext/enumerator/enumerator.c
+++ b/ext/enumerator/enumerator.c
@@ -20,7 +20,7 @@ static ID sym_each, sym_each_with_index, sym_each_slice, sym_each_cons;
static ID id_new, id_enum_obj, id_enum_method, id_enum_args;
static VALUE
-obj_enum_for(obj, enum_args)
+obj_to_enum(obj, enum_args)
VALUE obj, enum_args;
{
rb_ary_unshift(enum_args, obj);
@@ -172,7 +172,8 @@ Init_enumerator()
{
VALUE rb_mEnumerable;
- rb_define_method(rb_mKernel, "enum_for", obj_enum_for, -2);
+ rb_define_method(rb_mKernel, "to_enum", obj_to_enum, -2);
+ rb_define_method(rb_mKernel, "enum_for", obj_to_enum, -2);
rb_mEnumerable = rb_path2class("Enumerable");
diff --git a/ext/enumerator/enumerator.txt b/ext/enumerator/enumerator.txt
index 9a0f93a58..64c7d5022 100644
--- a/ext/enumerator/enumerator.txt
+++ b/ext/enumerator/enumerator.txt
@@ -38,6 +38,7 @@ Methods:
Requiring this module also adds some methods to the Object class:
+ to_enum(method = :each, *args)
enum_for(method = :each, *args)
Returns Enumerable::Enumerator.new(self, method, *args).
@@ -48,6 +49,10 @@ Requiring this module also adds some methods to the Object class:
enum = str.enum_for(:each_byte)
a = enum.map {|b| '%02x' % b } #=> ["78", "79", "7a"]
+ # protects an array from being modified
+ a = [1, 2, 3]
+ some_method(a.to_enum)
+
And the Enumerable module.
each_slice(n) {...}