[前][次][番号順一覧][スレッド一覧]

ruby-changes:21431

From: drbrain <ko1@a...>
Date: Wed, 19 Oct 2011 11:08:04 +0900 (JST)
Subject: [ruby-changes:21431] drbrain:r33480 (trunk): * enum.c: Reformat block args to a single standard, { |args| ... }.

drbrain	2011-10-19 11:07:50 +0900 (Wed, 19 Oct 2011)

  New Revision: 33480

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=33480

  Log:
    * enum.c: Reformat block args to a single standard, { |args| ... }.
      Patch by b t.  [Ruby 1.9 - Bug #5393]

  Modified files:
    trunk/ChangeLog
    trunk/enum.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 33479)
+++ ChangeLog	(revision 33480)
@@ -1,3 +1,8 @@
+Wed Oct 19 11:04:47 2011  Eric Hodel  <drbrain@s...>
+
+	* enum.c: Reformat block args to a single standard, { |args| ... }.
+	  Patch by b t.  [Ruby 1.9 - Bug #5393]
+
 Wed Oct 19 12:11:26 2011  Martin Bosslet  <Martin.Bosslet@g...>
 
 	* ext/openssl/ossl_ssl.c: Remove set, but unused variables.
Index: enum.c
===================================================================
--- enum.c	(revision 33479)
+++ enum.c	(revision 33480)
@@ -60,8 +60,8 @@
 
 /*
  *  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 @@
  *     (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 @@
 
 /*
  *  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 @@
  *  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 @@
 
 /*
  *  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 @@
  *
  *  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 @@
 
 /*
  *  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 @@
  *
  *  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 @@
 
 /*
  *  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 @@
  *  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 @@
 
 /*
  *  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 @@
 
 /*
  *  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 @@
 
 /*
  *  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 @@
 
 /*
  *  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 @@
  *  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 @@
  *
  *
  *     # 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 @@
 
 /*
  *  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 @@
  *
  *  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 @@
 
 /*
  *  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 @@
 
 /*
  *  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 @@
  *  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 @@
 
 /*
  *  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 @@
  *
  *     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 @@
  *  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 @@
  *  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 @@
  *
  *  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 @@
 
 /*
  *  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 @@
  *  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 @@
 
 /*
  *  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 @@
  *  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 @@
 
 /*
  *  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 @@
  *  <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 @@
 
 /*
  *  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 @@
 
 /*
  *  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 @@
 
 /*
  *  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 @@
 
 /*
  *  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 @@
  *
  *     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 @@
 
 /*
  *  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 @@
  *  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 @@
 
 /*
  *  call-seq:
- *     enum.max_by {|obj| block }   -> obj
- *     enum.max_by                  -> an_enumerator
+ *     enum.max_by { |obj| block } -> obj
+ *     enum (... truncated)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]