diff options
author | zzak <zzak@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-09-20 15:51:17 +0000 |
---|---|---|
committer | zzak <zzak@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-09-20 15:51:17 +0000 |
commit | df3e4b830677e41530402e3e5727b71551fbe666 (patch) | |
tree | 6616db52943c8d1948f624c0e32b5c0d0f11ed08 /enumerator.c | |
parent | b8d053030edfff3d5c282eaee47b2789813db07f (diff) |
* enumerator.c: [DOC] Enumerator#each arguments documentation [GH-388]
Patch by @kachick https://github.com/ruby/ruby/pull/388
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43000 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'enumerator.c')
-rw-r--r-- | enumerator.c | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/enumerator.c b/enumerator.c index 6f3de864a0..5794454f16 100644 --- a/enumerator.c +++ b/enumerator.c @@ -434,10 +434,38 @@ enumerator_block_call(VALUE obj, rb_block_call_func *func, VALUE arg) /* * call-seq: - * enum.each {...} + * enum.each { |elm| block } -> obj + * enum.each -> enum + * enum.each(*appending_args) { |elm| block } -> obj + * enum.each(*appending_args) -> an_enumerator * - * Iterates over the block according to how this Enumerable was constructed. - * If no block is given, returns self. + * Iterates over the block according to how this Enumerator was constructed. + * If no block and no arguments are given, returns self. + * + * === Examples + * + * "Hello, world!".scan(/\w+/) #=> ["Hello", "world"] + * "Hello, world!".to_enum(:scan, /\w+/).to_a #=> ["Hello", "world"] + * "Hello, world!".to_enum(:scan).each(/\w+/).to_a #=> ["Hello", "world"] + * + * obj = Object.new + * + * def obj.each_arg(a, b=:b, *rest) + * yield a + * yield b + * yield rest + * :method_returned + * end + * + * enum = obj.to_enum :each_arg, :a, :x + * + * enum.each.to_a #=> [:a, :x, []] + * enum.each.equal?(enum) #=> true + * enum.each { |elm| elm } #=> :method_returned + * + * enum.each(:y, :z).to_a #=> [:a, :x, [:y, :z]] + * enum.each(:y, :z).equal?(enum) #=> false + * enum.each(:y, :z) { |elm| elm } #=> :method_returned * */ static VALUE |