diff options
author | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-10-19 02:07:50 +0000 |
---|---|---|
committer | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-10-19 02:07:50 +0000 |
commit | 2a4ce0757d691199ea65ca36d59803280ff1b42a (patch) | |
tree | 2ea92d36d91b773c35eb8795b58b132c79722d1b /enum.c | |
parent | dc56a45996a25215873455473f9f2e22cd985247 (diff) |
* enum.c: Reformat block args to a single standard, { |args| ... }.
Patch by b t. [Ruby 1.9 - Bug #5393]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33480 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'enum.c')
-rw-r--r-- | enum.c | 354 |
1 files changed, 177 insertions, 177 deletions
@@ -60,8 +60,8 @@ grep_iter_i(VALUE i, VALUE args, int argc, VALUE *argv) /* * call-seq: - * enum.grep(pattern) -> array - * enum.grep(pattern) {| obj | block } -> array + * enum.grep(pattern) -> array + * enum.grep(pattern) { |obj| block } -> array * * Returns an array of every element in <i>enum</i> for which * <code>Pattern === element</code>. If the optional <em>block</em> is @@ -71,7 +71,7 @@ grep_iter_i(VALUE i, VALUE args, int argc, VALUE *argv) * (1..100).grep 38..44 #=> [38, 39, 40, 41, 42, 43, 44] * c = IO.constants * c.grep(/SEEK/) #=> [:SEEK_SET, :SEEK_CUR, :SEEK_END] - * res = c.grep(/SEEK/) {|v| IO.const_get(v) } + * res = c.grep(/SEEK/) { |v| IO.const_get(v) } * res #=> [0, 1, 2] * */ @@ -125,9 +125,9 @@ count_all_i(VALUE i, VALUE memop, int argc, VALUE *argv) /* * call-seq: - * enum.count -> int - * enum.count(item) -> int - * enum.count {| obj | block } -> int + * enum.count -> int + * enum.count(item) -> int + * enum.count { |obj| block } -> int * * Returns the number of items in <i>enum</i> if it responds to a #size call, * otherwise the items are counted through enumeration. If an argument is @@ -136,9 +136,9 @@ count_all_i(VALUE i, VALUE memop, int argc, VALUE *argv) * true value. * * ary = [1, 2, 4, 2] - * ary.count #=> 4 - * ary.count(2) #=> 2 - * ary.count{|x|x%2==0} #=> 3 + * ary.count #=> 4 + * ary.count(2) #=> 2 + * ary.count{ |x| x%2==0 } #=> 3 * */ @@ -183,10 +183,10 @@ find_i(VALUE i, VALUE *memo, int argc, VALUE *argv) /* * call-seq: - * enum.detect(ifnone = nil) {| obj | block } -> obj or nil - * enum.find(ifnone = nil) {| obj | block } -> obj or nil - * enum.detect(ifnone = nil) -> an_enumerator - * enum.find(ifnone = nil) -> an_enumerator + * enum.detect(ifnone = nil) { |obj| block } -> obj or nil + * enum.find(ifnone = nil) { |obj| block } -> obj or nil + * enum.detect(ifnone = nil) -> an_enumerator + * enum.find(ifnone = nil) -> an_enumerator * * Passes each entry in <i>enum</i> to <em>block</em>. Returns the * first for which <em>block</em> is not false. If no @@ -195,8 +195,8 @@ find_i(VALUE i, VALUE *memo, int argc, VALUE *argv) * * If no block is given, an enumerator is returned instead. * - * (1..10).detect {|i| i % 5 == 0 and i % 7 == 0 } #=> nil - * (1..100).detect {|i| i % 5 == 0 and i % 7 == 0 } #=> 35 + * (1..10).detect { |i| i % 5 == 0 and i % 7 == 0 } #=> nil + * (1..100).detect { |i| i % 5 == 0 and i % 7 == 0 } #=> 35 * */ @@ -248,9 +248,9 @@ find_index_iter_i(VALUE i, VALUE memop, int argc, VALUE *argv) /* * call-seq: - * enum.find_index(value) -> int or nil - * enum.find_index {| obj | block } -> int or nil - * enum.find_index -> an_enumerator + * enum.find_index(value) -> int or nil + * enum.find_index { |obj| block } -> int or nil + * enum.find_index -> an_enumerator * * Compares each entry in <i>enum</i> with <em>value</em> or passes * to <em>block</em>. Returns the index for the first for which the @@ -259,8 +259,8 @@ find_index_iter_i(VALUE i, VALUE memop, int argc, VALUE *argv) * * If neither block nor argument is given, an enumerator is returned instead. * - * (1..10).find_index {|i| i % 5 == 0 and i % 7 == 0 } #=> nil - * (1..100).find_index {|i| i % 5 == 0 and i % 7 == 0 } #=> 34 + * (1..10).find_index { |i| i % 5 == 0 and i % 7 == 0 } #=> nil + * (1..100).find_index { |i| i % 5 == 0 and i % 7 == 0 } #=> 34 * (1..100).find_index(50) #=> 49 * */ @@ -302,10 +302,10 @@ find_all_i(VALUE i, VALUE ary, int argc, VALUE *argv) /* * call-seq: - * enum.find_all {| obj | block } -> array - * enum.select {| obj | block } -> array - * enum.find_all -> an_enumerator - * enum.select -> an_enumerator + * enum.find_all { |obj| block } -> array + * enum.select { |obj| block } -> array + * enum.find_all -> an_enumerator + * enum.select -> an_enumerator * * Returns an array containing all elements of <i>enum</i> for which * <em>block</em> is not <code>false</code> (see also @@ -314,7 +314,7 @@ find_all_i(VALUE i, VALUE ary, int argc, VALUE *argv) * If no block is given, an enumerator is returned instead. * * - * (1..10).find_all {|i| i % 3 == 0 } #=> [3, 6, 9] + * (1..10).find_all { |i| i % 3 == 0 } #=> [3, 6, 9] * */ @@ -344,15 +344,15 @@ reject_i(VALUE i, VALUE ary, int argc, VALUE *argv) /* * call-seq: - * enum.reject {| obj | block } -> array - * enum.reject -> an_enumerator + * enum.reject { |obj| block } -> array + * enum.reject -> an_enumerator * * Returns an array for all elements of <i>enum</i> for which * <em>block</em> is false (see also <code>Enumerable#find_all</code>). * * If no block is given, an enumerator is returned instead. * - * (1..10).reject {|i| i % 3 == 0 } #=> [1, 2, 4, 5, 7, 8, 10] + * (1..10).reject { |i| i % 3 == 0 } #=> [1, 2, 4, 5, 7, 8, 10] * */ @@ -388,17 +388,17 @@ collect_all(VALUE i, VALUE ary, int argc, VALUE *argv) /* * call-seq: - * enum.collect {| obj | block } -> array - * enum.map {| obj | block } -> array - * enum.collect -> an_enumerator - * enum.map -> an_enumerator + * enum.collect { |obj| block } -> array + * enum.map { |obj| block } -> array + * enum.collect -> an_enumerator + * enum.map -> an_enumerator * * Returns a new array with the results of running <em>block</em> once * for every element in <i>enum</i>. * * If no block is given, an enumerator is returned instead. * - * (1..4).collect {|i| i*i } #=> [1, 4, 9, 16] + * (1..4).collect { |i| i*i } #=> [1, 4, 9, 16] * (1..4).collect { "cat" } #=> ["cat", "cat", "cat", "cat"] * */ @@ -435,17 +435,17 @@ flat_map_i(VALUE i, VALUE ary, int argc, VALUE *argv) /* * call-seq: - * enum.flat_map {| obj | block } -> array - * enum.collect_concat {| obj | block } -> array - * enum.flat_map -> an_enumerator - * enum.collect_concat -> an_enumerator + * enum.flat_map { |obj| block } -> array + * enum.collect_concat { |obj| block } -> array + * enum.flat_map -> an_enumerator + * enum.collect_concat -> an_enumerator * * Returns a new array with the concatenated results of running * <em>block</em> once for every element in <i>enum</i>. * * If no block is given, an enumerator is returned instead. * - * [[1,2],[3,4]].flat_map {|i| i } #=> [1, 2, 3, 4] + * [[1, 2], [3, 4]].flat_map { |i| i } #=> [1, 2, 3, 4] * */ @@ -464,8 +464,8 @@ enum_flat_map(VALUE obj) /* * call-seq: - * enum.to_a -> array - * enum.entries -> array + * enum.to_a -> array + * enum.entries -> array * * Returns an array containing the items in <i>enum</i>. * @@ -519,12 +519,12 @@ inject_op_i(VALUE i, VALUE p, int argc, VALUE *argv) * call-seq: * enum.inject(initial, sym) -> obj * enum.inject(sym) -> obj - * enum.inject(initial) {| memo, obj | block } -> obj - * enum.inject {| memo, obj | block } -> obj + * enum.inject(initial) { |memo, obj| block } -> obj + * enum.inject { |memo, obj| block } -> obj * enum.reduce(initial, sym) -> obj * enum.reduce(sym) -> obj - * enum.reduce(initial) {| memo, obj | block } -> obj - * enum.reduce {| memo, obj | block } -> obj + * enum.reduce(initial) { |memo, obj| block } -> obj + * enum.reduce { |memo, obj| block } -> obj * * Combines all elements of <i>enum</i> by applying a binary * operation, specified by a block or a symbol that names a @@ -544,18 +544,18 @@ inject_op_i(VALUE i, VALUE p, int argc, VALUE *argv) * * * # Sum some numbers - * (5..10).reduce(:+) #=> 45 + * (5..10).reduce(:+) #=> 45 * # Same using a block and inject - * (5..10).inject {|sum, n| sum + n } #=> 45 + * (5..10).inject { |sum, n| sum + n } #=> 45 * # Multiply some numbers - * (5..10).reduce(1, :*) #=> 151200 + * (5..10).reduce(1, :*) #=> 151200 * # Same using a block - * (5..10).inject(1) {|product, n| product * n } #=> 151200 + * (5..10).inject(1) { |product, n| product * n } #=> 151200 * # find the longest word - * longest = %w{ cat sheep bear }.inject do |memo,word| + * longest = %w{ cat sheep bear }.inject do |memo, word| * memo.length > word.length ? memo : word * end - * longest #=> "sheep" + * longest #=> "sheep" * */ static VALUE @@ -605,8 +605,8 @@ partition_i(VALUE i, VALUE *ary, int argc, VALUE *argv) /* * call-seq: - * enum.partition {| obj | block } -> [ true_array, false_array ] - * enum.partition -> an_enumerator + * enum.partition { |obj| block } -> [ true_array, false_array ] + * enum.partition -> an_enumerator * * Returns two arrays, the first containing the elements of * <i>enum</i> for which the block evaluates to true, the second @@ -614,7 +614,7 @@ partition_i(VALUE i, VALUE *ary, int argc, VALUE *argv) * * If no block is given, an enumerator is returned instead. * - * (1..6).partition {|v| v.even? } #=> [[2, 4, 6], [1, 3, 5]] + * (1..6).partition { |v| v.even? } #=> [[2, 4, 6], [1, 3, 5]] * */ @@ -654,8 +654,8 @@ group_by_i(VALUE i, VALUE hash, int argc, VALUE *argv) /* * call-seq: - * enum.group_by {| obj | block } -> a_hash - * enum.group_by -> an_enumerator + * enum.group_by { |obj| block } -> a_hash + * enum.group_by -> an_enumerator * * Groups the collection by result of the block. Returns a hash where the * keys are the evaluated result from the block and the values are @@ -747,8 +747,8 @@ enum_first(int argc, VALUE *argv, VALUE obj) /* * call-seq: - * enum.sort -> array - * enum.sort {| a, b | block } -> array + * enum.sort -> array + * enum.sort { |a, b| block } -> array * * Returns an array containing the items in <i>enum</i> sorted, * either according to their own <code><=></code> method, or by using @@ -758,8 +758,8 @@ enum_first(int argc, VALUE *argv, VALUE obj) * built-in Schwartzian Transform, useful when key computation or * comparison is expensive. * - * %w(rhea kea flea).sort #=> ["flea", "kea", "rhea"] - * (1..10).sort {|a,b| b <=> a} #=> [10, 9, 8, 7, 6, 5, 4, 3, 2, 1] + * %w(rhea kea flea).sort #=> ["flea", "kea", "rhea"] + * (1..10).sort { |a, b| b <=> a } #=> [10, 9, 8, 7, 6, 5, 4, 3, 2, 1] */ static VALUE @@ -822,15 +822,15 @@ sort_by_cmp(const void *ap, const void *bp, void *data) /* * call-seq: - * enum.sort_by {| obj | block } -> array - * enum.sort_by -> an_enumerator + * enum.sort_by { |obj| block } -> array + * enum.sort_by -> an_enumerator * * Sorts <i>enum</i> using a set of keys generated by mapping the * values in <i>enum</i> through the given block. * * If no block is given, an enumerator is returned instead. * - * %w{ apple pear fig }.sort_by {|word| word.length} + * %w{apple pear fig}.sort_by { |word| word.length} * #=> ["fig", "pear", "apple"] * * The current implementation of <code>sort_by</code> generates an @@ -840,11 +840,11 @@ sort_by_cmp(const void *ap, const void *bp, void *data) * * require 'benchmark' * - * a = (1..100000).map {rand(100000)} + * a = (1..100000).map { rand(100000) } * * Benchmark.bm(10) do |b| * b.report("Sort") { a.sort } - * b.report("Sort by") { a.sort_by {|a| a} } + * b.report("Sort by") { a.sort_by { |a| a } } * end * * <em>produces:</em> @@ -858,7 +858,7 @@ sort_by_cmp(const void *ap, const void *bp, void *data) * using the basic <code>sort</code> method. * * files = Dir["*"] - * sorted = files.sort {|a,b| File.new(a).mtime <=> File.new(b).mtime} + * sorted = files.sort { |a, b| File.new(a).mtime <=> File.new(b).mtime } * sorted #=> ["mon", "tues", "wed", "thurs"] * * This sort is inefficient: it generates two new <code>File</code> @@ -867,7 +867,7 @@ sort_by_cmp(const void *ap, const void *bp, void *data) * times directly. * * files = Dir["*"] - * sorted = files.sort { |a,b| + * sorted = files.sort { |a, b| * test(?M, a) <=> test(?M, b) * } * sorted #=> ["mon", "tues", "wed", "thurs"] @@ -887,7 +887,7 @@ sort_by_cmp(const void *ap, const void *bp, void *data) * * This is exactly what <code>sort_by</code> does internally. * - * sorted = Dir["*"].sort_by {|f| test(?M, f)} + * sorted = Dir["*"].sort_by { |f| test(?M, f) } * sorted #=> ["mon", "tues", "wed", "thurs"] */ @@ -964,7 +964,7 @@ DEFINE_ENUMFUNCS(all) /* * call-seq: - * enum.all? [{|obj| block } ] -> true or false + * enum.all? [{ |obj| block } ] -> true or false * * Passes each element of the collection to the given block. The method * returns <code>true</code> if the block never returns @@ -973,9 +973,9 @@ DEFINE_ENUMFUNCS(all) * cause #all? to return +true+ when none of the collection members are * +false+ or +nil+. * - * %w{ant bear cat}.all? {|word| word.length >= 3} #=> true - * %w{ant bear cat}.all? {|word| word.length >= 4} #=> false - * [ nil, true, 99 ].all? #=> false + * %w[ant bear cat].all? { |word| word.length >= 3 } #=> true + * %w[ant bear cat].all? { |word| word.length >= 4 } #=> false + * [nil, true, 99].all? #=> false * */ @@ -999,7 +999,7 @@ DEFINE_ENUMFUNCS(any) /* * call-seq: - * enum.any? [{|obj| block } ] -> true or false + * enum.any? [{ |obj| block }] -> true or false * * Passes each element of the collection to the given block. The method * returns <code>true</code> if the block ever returns a value other @@ -1008,9 +1008,9 @@ DEFINE_ENUMFUNCS(any) * will cause #any? to return +true+ if at least one of the collection * members is not +false+ or +nil+. * - * %w{ant bear cat}.any? {|word| word.length >= 3} #=> true - * %w{ant bear cat}.any? {|word| word.length >= 4} #=> true - * [ nil, true, 99 ].any? #=> true + * %w[ant bear cat].any? { |word| word.length >= 3 } #=> true + * %w[ant bear cat].any? { |word| word.length >= 4 } #=> true + * [nil, true, 99].any? #=> true * */ @@ -1039,7 +1039,7 @@ DEFINE_ENUMFUNCS(one) /* * call-seq: - * enum.one? [{|obj| block }] -> true or false + * enum.one? [{ |obj| block }] -> true or false * * Passes each element of the collection to the given block. The method * returns <code>true</code> if the block returns <code>true</code> @@ -1047,11 +1047,11 @@ DEFINE_ENUMFUNCS(one) * <code>true</code> only if exactly one of the collection members is * true. * - * %w{ant bear cat}.one? {|word| word.length == 4} #=> true - * %w{ant bear cat}.one? {|word| word.length > 4} #=> false - * %w{ant bear cat}.one? {|word| word.length < 4} #=> false - * [ nil, true, 99 ].one? #=> false - * [ nil, true, false ].one? #=> true + * %w{ant bear cat}.one? { |word| word.length == 4 } #=> true + * %w{ant bear cat}.one? { |word| word.length > 4 } #=> false + * %w{ant bear cat}.one? { |word| word.length < 4 } #=> false + * [ nil, true, 99 ].one? #=> false + * [ nil, true, false ].one? #=> true * */ @@ -1076,18 +1076,18 @@ DEFINE_ENUMFUNCS(none) /* * call-seq: - * enum.none? [{|obj| block }] -> true or false + * enum.none? [{ |obj| block }] -> true or false * * Passes each element of the collection to the given block. The method * returns <code>true</code> if the block never returns <code>true</code> * for all elements. If the block is not given, <code>none?</code> will return * <code>true</code> only if none of the collection members is true. * - * %w{ant bear cat}.none? {|word| word.length == 5} #=> true - * %w{ant bear cat}.none? {|word| word.length >= 4} #=> false - * [].none? #=> true - * [nil].none? #=> true - * [nil,false].none? #=> true + * %w{ant bear cat}.none? { |word| word.length == 5 } #=> true + * %w{ant bear cat}.none? { |word| word.length >= 4 } #=> false + * [].none? #=> true + * [nil].none? #=> true + * [nil, false].none? #=> true */ static VALUE enum_none(VALUE obj) @@ -1139,16 +1139,16 @@ min_ii(VALUE i, VALUE *memo, int argc, VALUE *argv) /* * call-seq: - * enum.min -> obj - * enum.min {| a,b | block } -> obj + * enum.min -> obj + * enum.min { |a, b| block } -> obj * * Returns the object in <i>enum</i> with the minimum value. The * first form assumes all objects implement <code>Comparable</code>; * the second uses the block to return <em>a <=> b</em>. * * a = %w(albatross dog horse) - * a.min #=> "albatross" - * a.min {|a,b| a.length <=> b.length } #=> "dog" + * a.min #=> "albatross" + * a.min { |a, b| a.length <=> b.length } #=> "dog" */ static VALUE @@ -1206,16 +1206,16 @@ max_ii(VALUE i, VALUE *memo, int argc, VALUE *argv) /* * call-seq: - * enum.max -> obj - * enum.max {|a,b| block } -> obj + * enum.max -> obj + * enum.max { |a, b| block } -> obj * * Returns the object in _enum_ with the maximum value. The * first form assumes all objects implement <code>Comparable</code>; * the second uses the block to return <em>a <=> b</em>. * * a = %w(albatross dog horse) - * a.max #=> "horse" - * a.max {|a,b| a.length <=> b.length } #=> "albatross" + * a.max #=> "horse" + * a.max { |a, b| a.length <=> b.length } #=> "albatross" */ static VALUE @@ -1345,8 +1345,8 @@ minmax_ii(VALUE i, VALUE _memo, int argc, VALUE *argv) /* * call-seq: - * enum.minmax -> [min,max] - * enum.minmax {|a,b| block } -> [min,max] + * enum.minmax -> [min, max] + * enum.minmax { |a, b| block } -> [min, max] * * Returns two elements array which contains the minimum and the * maximum value in the enumerable. The first form assumes all @@ -1355,7 +1355,7 @@ minmax_ii(VALUE i, VALUE _memo, int argc, VALUE *argv) * * a = %w(albatross dog horse) * a.minmax #=> ["albatross", "horse"] - * a.minmax {|a,b| a.length <=> b.length } #=> ["dog", "albatross"] + * a.minmax { |a, b| a.length <=> b.length } #=> ["dog", "albatross"] */ static VALUE @@ -1404,8 +1404,8 @@ min_by_i(VALUE i, VALUE *memo, int argc, VALUE *argv) /* * call-seq: - * enum.min_by {|obj| block } -> obj - * enum.min_by -> an_enumerator + * enum.min_by { |obj| block } -> obj + * enum.min_by -> an_enumerator * * Returns the object in <i>enum</i> that gives the minimum * value from the given block. @@ -1413,7 +1413,7 @@ min_by_i(VALUE i, VALUE *memo, int argc, VALUE *argv) * If no block is given, an enumerator is returned instead. * * a = %w(albatross dog horse) - * a.min_by {|x| x.length } #=> "dog" + * a.min_by { |x| x.length } #=> "dog" */ static VALUE @@ -1450,8 +1450,8 @@ max_by_i(VALUE i, VALUE *memo, int argc, VALUE *argv) /* * call-seq: - * enum.max_by {|obj| block } -> obj - * enum.max_by -> an_enumerator + * enum.max_by { |obj| block } -> obj + * enum.max_by -> an_enumerator * * Returns the object in <i>enum</i> that gives the maximum * value from the given block. @@ -1459,7 +1459,7 @@ max_by_i(VALUE i, VALUE *memo, int argc, VALUE *argv) * If no block is given, an enumerator is returned instead. * * a = %w(albatross dog horse) - * a.max_by {|x| x.length } #=> "albatross" + * a.max_by { |x| x.length } #=> "albatross" */ static VALUE @@ -1547,8 +1547,8 @@ minmax_by_i(VALUE i, VALUE _memo, int argc, VALUE *argv) /* * call-seq: - * enum.minmax_by {|obj| block } -> [min, max] - * enum.minmax_by -> an_enumerator + * enum.minmax_by { |obj| block } -> [min, max] + * enum.minmax_by -> an_enumerator * * Returns a two element array containing the objects in * <i>enum</i> that correspond to the minimum and maximum values respectively @@ -1557,7 +1557,7 @@ minmax_by_i(VALUE i, VALUE _memo, int argc, VALUE *argv) * If no block is given, an enumerator is returned instead. * * a = %w(albatross dog horse) - * a.minmax_by {|x| x.length } #=> ["dog", "albatross"] + * a.minmax_by { |x| x.length } #=> ["dog", "albatross"] */ static VALUE @@ -1623,8 +1623,8 @@ each_with_index_i(VALUE i, VALUE memo, int argc, VALUE *argv) /* * call-seq: - * enum.each_with_index(*args) {|obj, i| block } -> enum - * enum.each_with_index(*args) -> an_enumerator + * enum.each_with_index(*args) { |obj, i| block } -> enum + * enum.each_with_index(*args) -> an_enumerator * * Calls <em>block</em> with two arguments, the item and its index, * for each item in <i>enum</i>. Given arguments are passed through @@ -1633,7 +1633,7 @@ each_with_index_i(VALUE i, VALUE memo, int argc, VALUE *argv) * If no block is given, an enumerator is returned instead. * * hash = Hash.new - * %w(cat dog wombat).each_with_index {|item, index| + * %w(cat dog wombat).each_with_index { |item, index| * hash[item] = index * } * hash #=> {"cat"=>0, "dog"=>1, "wombat"=>2} @@ -1655,14 +1655,14 @@ enum_each_with_index(int argc, VALUE *argv, VALUE obj) /* * call-seq: - * enum.reverse_each(*args) {|item| block } -> enum - * enum.reverse_each(*args) -> an_enumerator + * enum.reverse_each(*args) { |item| block } -> enum + * enum.reverse_each(*args) -> an_enumerator * * Builds a temporary array and traverses that array in reverse order. * * If no block is given, an enumerator is returned instead. * - * (1..3).reverse_each {|v| p v } + * (1..3).reverse_each { |v| p v } * * produces: * @@ -1699,8 +1699,8 @@ each_val_i(VALUE i, VALUE p, int argc, VALUE *argv) /* * call-seq: - * enum.each_entry {|obj| block} -> enum - * enum.each_entry -> an_enumerator + * enum.each_entry { |obj| block } -> enum + * enum.each_entry -> an_enumerator * * Calls <i>block</i> once for each element in +self+, passing that * element as a parameter, converting multiple values from yield to an @@ -1712,11 +1712,11 @@ each_val_i(VALUE i, VALUE p, int argc, VALUE *argv) * include Enumerable * def each * yield 1 - * yield 1,2 + * yield 1, 2 * yield * end * end - * Foo.new.each_entry{|o| p o } + * Foo.new.each_entry{ |o| p o } * * produces: * @@ -1754,13 +1754,13 @@ each_slice_i(VALUE i, VALUE *memo, int argc, VALUE *argv) /* * call-seq: - * enum.each_slice(n) {...} -> nil - * enum.each_slice(n) -> an_enumerator + * enum.each_slice(n) { ... } -> nil + * enum.each_slice(n) -> an_enumerator * * Iterates the given block for each slice of <n> elements. If no * block is given, returns an enumerator. * - * (1..10).each_slice(3) {|a| p a} + * (1..10).each_slice(3) { |a| p a } * # outputs below * [1, 2, 3] * [4, 5, 6] @@ -1807,14 +1807,14 @@ each_cons_i(VALUE i, VALUE *memo, int argc, VALUE *argv) /* * call-seq: - * enum.each_cons(n) {...} -> nil + * enum.each_cons(n) { ... } -> nil * enum.each_cons(n) -> an_enumerator * * Iterates the given block for each array of consecutive <n> * elements. If no block is given, returns an enumerator. * * e.g.: - * (1..10).each_cons(3) {|a| p a} + * (1..10).each_cons(3) { |a| p a } * # outputs below * [1, 2, 3] * [2, 3, 4] @@ -1851,15 +1851,15 @@ each_with_object_i(VALUE i, VALUE memo, int argc, VALUE *argv) /* * call-seq: - * enum.each_with_object(obj) {|(*args), memo_obj| ... } -> obj - * enum.each_with_object(obj) -> an_enumerator + * enum.each_with_object(obj) { |(*args), memo_obj| ... } -> obj + * enum.each_with_object(obj) -> an_enumerator * * Iterates the given block for each element with an arbitrary * object given, and returns the initially given object. * * If no block is given, returns an enumerator. * - * evens = (1..10).each_with_object([]) {|i, a| a << i*2 } + * evens = (1..10).each_with_object([]) { |i, a| a << i*2 } * #=> [2, 4, 6, 8, 10, 12, 14, 16, 18, 20] * */ @@ -1952,8 +1952,8 @@ zip_i(VALUE val, NODE *memo, int argc, VALUE *argv) /* * call-seq: - * enum.zip(arg, ...) -> an_array_of_array - * enum.zip(arg, ...) {|arr| block } -> nil + * enum.zip(arg, ...) -> an_array_of_array + * enum.zip(arg, ...) { |arr| block } -> nil * * Takes one element from <i>enum</i> and merges corresponding * elements from each <i>args</i>. This generates a sequence of @@ -1967,9 +1967,9 @@ zip_i(VALUE val, NODE *memo, int argc, VALUE *argv) * a = [ 4, 5, 6 ] * b = [ 7, 8, 9 ] * - * [1,2,3].zip(a, b) #=> [[1, 4, 7], [2, 5, 8], [3, 6, 9]] - * [1,2].zip(a,b) #=> [[1, 4, 7], [2, 5, 8]] - * a.zip([1,2],[8]) #=> [[4, 1, 8], [5, 2, nil], [6, nil, nil]] + * [1, 2, 3].zip(a, b) #=> [[1, 4, 7], [2, 5, 8], [3, 6, 9]] + * [1, 2].zip(a, b) #=> [[1, 4, 7], [2, 5, 8]] + * a.zip([1, 2], [8]) #=> [[4, 1, 8], [5, 2, nil], [6, nil, nil]] * */ @@ -2055,8 +2055,8 @@ take_while_i(VALUE i, VALUE *ary, int argc, VALUE *argv) /* * call-seq: - * enum.take_while {|arr| block } -> array - * enum.take_while -> an_enumerator + * enum.take_while { |arr| block } -> array + * enum.take_while -> an_enumerator * * Passes elements to the block until the block returns +nil+ or +false+, * then stops iterating and returns an array of all prior elements. @@ -2064,7 +2064,7 @@ take_while_i(VALUE i, VALUE *ary, int argc, VALUE *argv) * If no block is given, an enumerator is returned instead. * * a = [1, 2, 3, 4, 5, 0] - * a.take_while {|i| i < 3 } #=> [1, 2] + * a.take_while { |i| i < 3 } #=> [1, 2] * */ @@ -2136,7 +2136,7 @@ drop_while_i(VALUE i, VALUE *args, int argc, VALUE *argv) /* * call-seq: - * enum.drop_while {|arr| block } -> array + * enum.drop_while { |arr| block } -> array * enum.drop_while -> an_enumerator * * Drops elements up to, but not including, the first element for @@ -2146,7 +2146,7 @@ drop_while_i(VALUE i, VALUE *args, int argc, VALUE *argv) * If no block is given, an enumerator is returned instead. * * a = [1, 2, 3, 4, 5, 0] - * a.drop_while {|i| i < 3 } #=> [3, 4, 5, 0] + * a.drop_while { |i| i < 3 } #=> [3, 4, 5, 0] * */ @@ -2174,7 +2174,7 @@ cycle_i(VALUE i, VALUE ary, int argc, VALUE *argv) /* * call-seq: - * enum.cycle(n=nil) {|obj| block } -> nil + * enum.cycle(n=nil) { |obj| block } -> nil * enum.cycle(n=nil) -> an_enumerator * * Calls <i>block</i> for each element of <i>enum</i> repeatedly _n_ @@ -2188,8 +2188,8 @@ cycle_i(VALUE i, VALUE ary, int argc, VALUE *argv) * If no block is given, an enumerator is returned instead. * * a = ["a", "b", "c"] - * a.cycle {|x| puts x } # print, a, b, c, a, b, c,.. forever. - * a.cycle(2) {|x| puts x } # print, a, b, c, a, b, c. + * a.cycle { |x| puts x } # print, a, b, c, a, b, c,.. forever. + * a.cycle(2) { |x| puts x } # print, a, b, c, a, b, c. * */ @@ -2305,8 +2305,8 @@ chunk_i(VALUE yielder, VALUE enumerator, int argc, VALUE *argv) /* * call-seq: - * enum.chunk {|elt| ... } -> an_enumerator - * enum.chunk(initial_state) {|elt, state| ... } -> an_enumerator + * enum.chunk { |elt| ... } -> an_enumerator + * enum.chunk(initial_state) { |elt, state| ... } -> an_enumerator * * Creates an enumerator for each chunked elements. * The consecutive elements which have same block value are chunked. @@ -2314,15 +2314,15 @@ chunk_i(VALUE yielder, VALUE enumerator, int argc, VALUE *argv) * The result enumerator yields the block value and an array of chunked elements. * So "each" method can be called as follows. * - * enum.chunk {|elt| key }.each {|key, ary| ... } - * enum.chunk(initial_state) {|elt, state| key }.each {|key, ary| ... } + * enum.chunk { |elt| key }.each { |key, ary| ... } + * enum.chunk(initial_state) { |elt, state| key }.each { |key, ary| ... } * * For example, consecutive even numbers and odd numbers can be * splitted as follows. * - * [3,1,4,1,5,9,2,6,5,3,5].chunk {|n| + * [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5].chunk { |n| * n.even? - * }.each {|even, ary| + * }.each { |even, ary| * p [even, ary] * } * #=> [false, [3, 1]] @@ -2334,8 +2334,8 @@ chunk_i(VALUE yielder, VALUE enumerator, int argc, VALUE *argv) * This method is especially useful for sorted series of elements. * The following example counts words for each initial letter. * - * open("/usr/share/dict/words", "r:iso-8859-1") {|f| - * f.chunk {|line| line.ord }.each {|ch, lines| p [ch.chr, lines.length] } + * open("/usr/share/dict/words", "r:iso-8859-1") { |f| + * f.chunk { |line| line.ord }.each { |ch, lines| p [ch.chr, lines.length] } * } * #=> ["\n", 1] * # ["A", 1327] @@ -2353,10 +2353,10 @@ chunk_i(VALUE yielder, VALUE enumerator, int argc, VALUE *argv) * For example, the sequence of hyphens in svn log can be eliminated as follows. * * sep = "-"*72 + "\n" - * IO.popen("svn log README") {|f| - * f.chunk {|line| + * IO.popen("svn log README") { |f| + * f.chunk { |line| * line != sep || nil - * }.each {|_, lines| + * }.each { |_, lines| * pp lines * } * } @@ -2372,9 +2372,9 @@ chunk_i(VALUE yielder, VALUE enumerator, int argc, VALUE *argv) * * paragraphs separated by empty lines can be parsed as follows. * - * File.foreach("README").chunk {|line| + * File.foreach("README").chunk { |line| * /\A\s*\z/ !~ line || nil - * }.each {|_, lines| + * }.each { |_, lines| * pp lines * } * @@ -2383,8 +2383,8 @@ chunk_i(VALUE yielder, VALUE enumerator, int argc, VALUE *argv) * pass other lines, chunk can be used as follows. * * pat = /\A[A-Z][A-Za-z0-9_]+\#/ - * open(filename) {|f| - * f.chunk {|line| pat =~ line ? $& : :_alone }.each {|key, lines| + * open(filename) { |f| + * f.chunk { |line| pat =~ line ? $& : :_alone }.each { |key, lines| * if key != :_alone * print lines.sort.join('') * else @@ -2480,9 +2480,9 @@ slicebefore_i(VALUE yielder, VALUE enumerator, int argc, VALUE *argv) /* * call-seq: - * enum.slice_before(pattern) -> an_enumerator - * enum.slice_before {|elt| bool } -> an_enumerator - * enum.slice_before(initial_state) {|elt, state| bool } -> an_enumerator + * enum.slice_before(pattern) -> an_enumerator + * enum.slice_before { |elt| bool } -> an_enumerator + * enum.slice_before(initial_state) { |elt, state| bool } -> an_enumerator * * Creates an enumerator for each chunked elements. * The beginnings of chunks are defined by _pattern_ and the block. @@ -2498,9 +2498,9 @@ slicebefore_i(VALUE yielder, VALUE enumerator, int argc, VALUE *argv) * method. * +each+ method can be called as follows. * - * enum.slice_before(pattern).each {|ary| ... } - * enum.slice_before {|elt| bool }.each {|ary| ... } - * enum.slice_before(initial_state) {|elt, state| bool }.each {|ary| ... } + * enum.slice_before(pattern).each { |ary| ... } + * enum.slice_before { |elt| bool }.each { |ary| ... } + * enum.slice_before(initial_state) { |elt, state| bool }.each { |ary| ... } * * Other methods of Enumerator class and Enumerable module, * such as map, etc., are also usable. @@ -2509,20 +2509,20 @@ slicebefore_i(VALUE yielder, VALUE enumerator, int argc, VALUE *argv) * follows. * * # iterate over ChangeLog entries. - * open("ChangeLog") {|f| - * f.slice_before(/\A\S/).each {|e| pp e} + * open("ChangeLog") { |f| + * f.slice_before(/\A\S/).each { |e| pp e } * } * * # same as above. block is used instead of pattern argument. - * open("ChangeLog") {|f| - * f.slice_before {|line| /\A\S/ === line }.each {|e| pp e} + * open("ChangeLog") { |f| + * f.slice_before { |line| /\A\S/ === line }.each { |e| pp e } * } * * "svn proplist -R" produces multiline output for each file. * They can be chunked as follows: * - * IO.popen([{"LC_ALL"=>"C"}, "svn", "proplist", "-R"]) {|f| - * f.lines.slice_before(/\AProp/).each {|lines| p lines } + * IO.popen([{"LC_ALL"=>"C"}, "svn", "proplist", "-R"]) { |f| + * f.lines.slice_before(/\AProp/).each { |lines| p lines } * } * #=> ["Properties on '.':\n", " svn:ignore\n", " svk:merge\n"] * # ["Properties on 'goruby.c':\n", " svn:eol-style\n"] @@ -2535,12 +2535,12 @@ slicebefore_i(VALUE yielder, VALUE enumerator, int argc, VALUE *argv) * For example, three or more consecutive increasing numbers can be squashed * as follows: * - * a = [0,2,3,4,6,7,9] + * a = [0, 2, 3, 4, 6, 7, 9] * prev = a[0] - * p a.slice_before {|e| + * p a.slice_before { |e| * prev, prev2 = e, prev * prev2 + 1 != e - * }.map {|es| + * }.map { |es| * es.length <= 2 ? es.join(",") : "#{es.first}-#{es.last}" * }.join(",") * #=> "0,2-4,6,7,9" @@ -2558,7 +2558,7 @@ slicebefore_i(VALUE yielder, VALUE enumerator, int argc, VALUE *argv) * # this assumes all characters have same width. * def wordwrap(words, maxwidth) * # if cols is a local variable, 2nd "each" may start with non-zero cols. - * words.slice_before(cols: 0) {|w, h| + * words.slice_before(cols: 0) { |w, h| * h[:cols] += 1 if h[:cols] != 0 * h[:cols] += w.length * if maxwidth < h[:cols] @@ -2572,7 +2572,7 @@ slicebefore_i(VALUE yielder, VALUE enumerator, int argc, VALUE *argv) * text = (1..20).to_a.join(" ") * enum = wordwrap(text.split(/\s+/), 10) * puts "-"*10 - * enum.each {|ws| puts ws.join(" ") } + * enum.each { |ws| puts ws.join(" ") } * puts "-"*10 * #=> ---------- * # 1 2 3 4 5 @@ -2587,16 +2587,16 @@ slicebefore_i(VALUE yielder, VALUE enumerator, int argc, VALUE *argv) * So each mail can be extracted by slice before Unix From line. * * # parse mbox - * open("mbox") {|f| - * f.slice_before {|line| + * open("mbox") { |f| + * f.slice_before { |line| * line.start_with? "From " - * }.each {|mail| + * }.each { |mail| * unix_from = mail.shift * i = mail.index("\n") * header = mail[0...i] * body = mail[(i+1)..-1] * body.pop if body.last == "\n" - * fields = header.slice_before {|line| !" \t".include?(line[0]) }.to_a + * fields = header.slice_before { |line| !" \t".include?(line[0]) }.to_a * p unix_from * pp fields * pp body @@ -2604,12 +2604,12 @@ slicebefore_i(VALUE yielder, VALUE enumerator, int argc, VALUE *argv) * } * * # split mails in mbox (slice before Unix From line after an empty line) - * open("mbox") {|f| - * f.slice_before(emp: true) {|line,h| + * open("mbox") { |f| + * f.slice_before(emp: true) { |line, h| * prevemp = h[:emp] * h[:emp] = line == "\n" * prevemp && line.start_with?("From ") - * }.each {|mail| + * }.each { |mail| * mail.pop if mail.last == "\n" * pp mail * } |