From 464c1676fa87c1adb18d9b46d2aa97ace6fc7357 Mon Sep 17 00:00:00 2001 From: burningTyger Date: Tue, 4 Oct 2011 08:30:27 +0200 Subject: [PATCH] more consistent doc block style for enum.c --- enum.c | 342 ++++++++++++++++++++++++++++++++-------------------------------- 1 files changed, 171 insertions(+), 171 deletions(-) diff --git a/enum.c b/enum.c index b9d34d8..91ca407 100644 --- a/enum.c +++ b/enum.c @@ -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 enum for which * Pattern === element. If the optional block 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 enum, where #size is called * if it responds to it, otherwise the items are counted through @@ -136,9 +136,9 @@ count_all_i(VALUE i, VALUE memop, int argc, VALUE *argv) * given, counts the number of elements yielding a 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 enum to block. Returns the * first for which block 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 enum with value or passes * to block. 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 enum for which * block is not false (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 enum for which * block is false (see also Enumerable#find_all). * * 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 block once * for every element in enum. * * 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 * block once for every element in enum. * * 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 enum. * @@ -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 enum by applying a binary * operation, specified by a block or a symbol that names a @@ -545,18 +545,18 @@ inject_op_i(VALUE i, VALUE p, int argc, VALUE *argv) * Examples: * * # 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| * memo.length > word.length ? memo : word * end - * longest #=> "sheep" + * longest #=> "sheep" * */ static VALUE @@ -606,8 +606,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 * enum for which the block evaluates to true, the second @@ -615,7 +615,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]] * */ @@ -655,8 +655,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 * * Returns a hash, which keys are evaluated result from the * block, and values are arrays of elements in enum @@ -664,7 +664,7 @@ group_by_i(VALUE i, VALUE hash, int argc, VALUE *argv) * * If no block is given, an enumerator is returned instead. * - * (1..6).group_by {|i| i%3} #=> {0=>[3, 6], 1=>[1, 4], 2=>[2, 5]} + * (1..6).group_by { |i| i%3 } #=> {0=>[3, 6], 1=>[1, 4], 2=>[2, 5]} * */ @@ -748,8 +748,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 enum sorted, * either according to their own <=> method, or by using @@ -759,8 +759,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 @@ -823,15 +823,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 enum using a set of keys generated by mapping the * values in enum 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 sort_by generates an @@ -841,11 +841,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 * * produces: @@ -859,7 +859,7 @@ sort_by_cmp(const void *ap, const void *bp, void *data) * using the basic sort 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 File @@ -888,7 +888,7 @@ sort_by_cmp(const void *ap, const void *bp, void *data) * * This is exactly what sort_by does internally. * - * sorted = Dir["*"].sort_by {|f| test(?M, f)} + * sorted = Dir["*"].sort_by { |f| test(?M, f) } * sorted #=> ["mon", "tues", "wed", "thurs"] */ @@ -965,18 +965,18 @@ 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 true if the block never returns * false or nil. If the block is not given, - * Ruby adds an implicit block of {|obj| obj} (that is + * Ruby adds an implicit block of { |obj| obj } (that is * all? will return true only if 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 * */ @@ -1000,19 +1000,19 @@ 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 true if the block ever returns a value other * than false or nil. If the block is not - * given, Ruby adds an implicit block of {|obj| obj} (that + * given, Ruby adds an implicit block of { |obj| obj } (that * is any? will 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 * */ @@ -1041,7 +1041,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 true if the block returns true @@ -1049,11 +1049,11 @@ DEFINE_ENUMFUNCS(one) * true 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 * */ @@ -1078,18 +1078,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 true if the block never returns true * for all elements. If the block is not given, none? will return * true 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) @@ -1141,8 +1141,8 @@ 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 enum with the minimum value. The * first form assumes all objects implement Comparable; @@ -1150,7 +1150,7 @@ min_ii(VALUE i, VALUE *memo, int argc, VALUE *argv) * * a = %w(albatross dog horse) * a.min #=> "albatross" - * a.min {|a,b| a.length <=> b.length } #=> "dog" + * a.min { |a,b| a.length <=> b.length } #=> "dog" */ static VALUE @@ -1208,8 +1208,8 @@ 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 Comparable; @@ -1217,7 +1217,7 @@ max_ii(VALUE i, VALUE *memo, int argc, VALUE *argv) * * a = %w(albatross dog horse) * a.max #=> "horse" - * a.max {|a,b| a.length <=> b.length } #=> "albatross" + * a.max { |a,b| a.length <=> b.length } #=> "albatross" */ static VALUE @@ -1347,8 +1347,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 @@ -1357,7 +1357,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 @@ -1406,8 +1406,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 enum that gives the minimum * value from the given block. @@ -1415,7 +1415,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 @@ -1452,8 +1452,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 enum that gives the maximum * value from the given block. @@ -1461,7 +1461,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 @@ -1549,8 +1549,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 two elements array array containing the objects in * enum that gives the minimum and maximum values respectively @@ -1559,7 +1559,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 @@ -1625,8 +1625,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 block with two arguments, the item and its index, * for each item in enum. Given arguments are passed through @@ -1635,7 +1635,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} @@ -1657,14 +1657,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: * @@ -1701,8 +1701,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 block once for each element in +self+, passing that * element as a parameter, converting multiple values from yield to an @@ -1718,7 +1718,7 @@ each_val_i(VALUE i, VALUE p, int argc, VALUE *argv) * yield * end * end - * Foo.new.each_entry{|o| p o } + * Foo.new.each_entry{ |o| p o } * * produces: * @@ -1756,14 +1756,14 @@ 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 elements. If no * block is given, returns an enumerator. * * e.g.: - * (1..10).each_slice(3) {|a| p a} + * (1..10).each_slice(3) { |a| p a } * # outputs below * [1, 2, 3] * [4, 5, 6] @@ -1810,14 +1810,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 * 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] @@ -1854,8 +1854,8 @@ 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. @@ -1863,7 +1863,7 @@ each_with_object_i(VALUE i, VALUE memo, int argc, VALUE *argv) * If no block is given, returns an enumerator. * * e.g.: - * 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] * */ @@ -1956,8 +1956,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 enum and merges corresponding * elements from each args. This generates a sequence of @@ -2059,8 +2059,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. @@ -2068,7 +2068,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] * */ @@ -2140,7 +2140,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 @@ -2150,7 +2150,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] * */ @@ -2178,7 +2178,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 block for each element of enum repeatedly _n_ @@ -2192,8 +2192,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. * */ @@ -2309,8 +2309,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. @@ -2318,15 +2318,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]] @@ -2338,8 +2338,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] @@ -2357,10 +2357,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 * } * } @@ -2376,9 +2376,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 * } * @@ -2387,8 +2387,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 @@ -2484,9 +2484,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. @@ -2502,9 +2502,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. @@ -2513,20 +2513,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"] @@ -2541,10 +2541,10 @@ slicebefore_i(VALUE yielder, VALUE enumerator, int argc, VALUE *argv) * * 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" @@ -2562,7 +2562,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] @@ -2576,7 +2576,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 @@ -2591,16 +2591,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 @@ -2608,12 +2608,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 * } -- 1.7.7