1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ext/tk/lib/tk/canvas.rb (TkCanvasItemConfig::__item_val2ruby_optkeys):

typo fixed.  [ruby-talk:162187]

* ext/tk/lib/tk/menu.rb (TkMenuEntryConfig::__item_val2ruby_optkeys):
  ditto.  [ruby-core:06359]

* ext/enumerator/enumerator.c: applied documentation patch from
  James Edward Gray II <james@grayproductions.net>.
  [ruby-core:06348]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@9450 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2005-10-24 00:07:01 +00:00
parent 0a1a47235e
commit 082cb4b2b3
6 changed files with 126 additions and 4 deletions

View file

@ -15,10 +15,34 @@
#include "ruby.h"
#include "node.h"
/*
* Document-class: Enumerable::Enumerator
*
* A class which provides a method `each' to be used as an Enumerable
* object.
*/
static VALUE rb_cEnumerator;
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;
/*
* call-seq:
* obj.to_enum(method = :each, *args)
* obj.enum_for(method = :each, *args)
*
* Returns Enumerable::Enumerator.new(self, method, *args).
*
* e.g.:
* str = "xyz"
*
* 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)
*
*/
static VALUE
obj_to_enum(obj, enum_args)
VALUE obj, enum_args;
@ -28,6 +52,13 @@ obj_to_enum(obj, enum_args)
return rb_apply(rb_cEnumerator, id_new, enum_args);
}
/*
* call-seq:
* enum_with_index
*
* Returns Enumerable::Enumerator.new(self, :each_with_index).
*
*/
static VALUE
enumerator_enum_with_index(obj)
VALUE obj;
@ -53,6 +84,21 @@ each_slice_i(val, memo)
return Qnil;
}
/*
* call-seq:
* e.each_slice(n) {...}
*
* Iterates the given block for each slice of <n> elements.
*
* e.g.:
* (1..10).each_slice(3) {|a| p a}
* # outputs below
* [1, 2, 3]
* [4, 5, 6]
* [7, 8, 9]
* [10]
*
*/
static VALUE
enum_each_slice(obj, n)
VALUE obj, n;
@ -73,6 +119,13 @@ enum_each_slice(obj, n)
return Qnil;
}
/*
* call-seq:
* e.enum_slice(n)
*
* Returns Enumerable::Enumerator.new(self, :each_slice, n).
*
*/
static VALUE
enumerator_enum_slice(obj, n)
VALUE obj, n;
@ -98,6 +151,26 @@ each_cons_i(val, memo)
return Qnil;
}
/*
* call-seq:
* each_cons(n) {...}
*
* Iterates the given block for each array of consecutive <n>
* elements.
*
* e.g.:
* (1..10).each_cons(3) {|a| p a}
* # outputs below
* [1, 2, 3]
* [2, 3, 4]
* [3, 4, 5]
* [4, 5, 6]
* [5, 6, 7]
* [6, 7, 8]
* [7, 8, 9]
* [8, 9, 10]
*
*/
static VALUE
enum_each_cons(obj, n)
VALUE obj, n;
@ -113,6 +186,13 @@ enum_each_cons(obj, n)
return Qnil;
}
/*
* call-seq:
* e.enum_cons(n)
*
* Returns Enumerable::Enumerator.new(self, :each_cons, n).
*
*/
static VALUE
enumerator_enum_cons(obj, n)
VALUE obj, n;
@ -120,6 +200,21 @@ enumerator_enum_cons(obj, n)
return rb_funcall(rb_cEnumerator, id_new, 3, obj, sym_each_cons, n);
}
/*
* call-seq:
* Enumerable::Enumerator.new(obj, method = :each, *args)
*
* Creates a new Enumerable::Enumerator object, which is to be
* used as an Enumerable object using the given object's given
* method with the given arguments.
*
* e.g.:
* str = "xyz"
*
* enum = Enumerable::Enumerator.new(str, :each_byte)
* a = enum.map {|b| '%02x' % b } #=> ["78", "79", "7a"]
*
*/
static VALUE
enumerator_initialize(argc, argv, obj)
int argc;
@ -147,6 +242,14 @@ enumerator_iter(memo)
return rb_apply(memo->u1.value, memo->u2.id, memo->u3.value);
}
/*
* call-seq:
* enum.each {...}
*
* Iterates the given block using the object and the method specified
* in the first place.
*
*/
static VALUE
enumerator_each(obj)
VALUE obj;