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

ruby-changes:44026

From: mrkn <ko1@a...>
Date: Thu, 8 Sep 2016 11:33:24 +0900 (JST)
Subject: [ruby-changes:44026] mrkn:r56099 (trunk): hash.c: map_v -> transform_values

mrkn	2016-09-08 11:33:18 +0900 (Thu, 08 Sep 2016)

  New Revision: 56099

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56099

  Log:
    hash.c: map_v -> transform_values
    
    * hash.c (rb_hash_transform_values, rb_hash_transform_values_bang):
      Rename map_v to transform_values.
      [Feature #12512] [ruby-core:76095]
    
    * test/ruby/test_hash.rb: ditto.

  Modified files:
    trunk/ChangeLog
    trunk/hash.c
    trunk/test/ruby/test_hash.rb
Index: hash.c
===================================================================
--- hash.c	(revision 56098)
+++ hash.c	(revision 56099)
@@ -1788,7 +1788,7 @@ rb_hash_each_pair(VALUE hash) https://github.com/ruby/ruby/blob/trunk/hash.c#L1788
 }
 
 static int
-map_v_i(VALUE key, VALUE value, VALUE result)
+transform_values_i(VALUE key, VALUE value, VALUE result)
 {
     VALUE new_value = rb_yield(value);
     rb_hash_aset(result, key, new_value);
@@ -1797,29 +1797,29 @@ map_v_i(VALUE key, VALUE value, VALUE re https://github.com/ruby/ruby/blob/trunk/hash.c#L1797
 
 /*
  *  call-seq:
- *     hsh.map_v {|value| block } -> hsh
- *     hsh.map_v                  -> an_enumerator
+ *     hsh.transform_values {|value| block } -> hsh
+ *     hsh.transform_values                  -> an_enumerator
  *
  *  Return a new with the results of running block once for every value.
  *  This method does not change the keys.
  *
  *     h = { a: 1, b: 2, c: 3 }
- *     h.map_v {|v| v * v + 1 }  #=> { a: 2, b: 5, c: 10 }
- *     h.map_v(&:to_s)           #=> { a: "1", b: "2", c: "3" }
- *     h.map_v.with_index {|v, i| "#{v}.#{i}" }
- *                               #=> { a: "1.0", b: "2.1", c: "3.2" }
+ *     h.transform_values {|v| v * v + 1 }  #=> { a: 2, b: 5, c: 10 }
+ *     h.transform_values(&:to_s)           #=> { a: "1", b: "2", c: "3" }
+ *     h.transform_values.with_index {|v, i| "#{v}.#{i}" }
+ *                                          #=> { a: "1.0", b: "2.1", c: "3.2" }
  *
  *  If no block is given, an enumerator is returned instead.
  */
 static VALUE
-rb_hash_map_v(VALUE hash)
+rb_hash_transform_values(VALUE hash)
 {
     VALUE result;
 
     RETURN_SIZED_ENUMERATOR(hash, 0, 0, hash_enum_size);
     result = rb_hash_new();
     if (!RHASH_EMPTY_P(hash)) {
-        rb_hash_foreach(hash, map_v_i, result);
+        rb_hash_foreach(hash, transform_values_i, result);
     }
 
     return result;
@@ -1827,27 +1827,27 @@ rb_hash_map_v(VALUE hash) https://github.com/ruby/ruby/blob/trunk/hash.c#L1827
 
 /*
  *  call-seq:
- *     hsh.map_v! {|value| block } -> hsh
- *     hsh.map_v!                  -> an_enumerator
+ *     hsh.transform_values! {|value| block } -> hsh
+ *     hsh.transform_values!                  -> an_enumerator
  *
  *  Return a new with the results of running block once for every value.
  *  This method does not change the keys.
  *
  *     h = { a: 1, b: 2, c: 3 }
- *     h.map_v! {|v| v * v + 1 }  #=> { a: 2, b: 5, c: 10 }
- *     h.map_v!(&:to_s)           #=> { a: "1", b: "2", c: "3" }
- *     h.map_v!.with_index {|v, i| "#{v}.#{i}" }
- *                                #=> { a: "1.0", b: "2.1", c: "3.2" }
+ *     h.transform_values! {|v| v * v + 1 }  #=> { a: 2, b: 5, c: 10 }
+ *     h.transform_values!(&:to_s)           #=> { a: "1", b: "2", c: "3" }
+ *     h.transform_values!.with_index {|v, i| "#{v}.#{i}" }
+ *                                           #=> { a: "1.0", b: "2.1", c: "3.2" }
  *
  *  If no block is given, an enumerator is returned instead.
  */
 static VALUE
-rb_hash_map_v_bang(VALUE hash)
+rb_hash_transform_values_bang(VALUE hash)
 {
     RETURN_SIZED_ENUMERATOR(hash, 0, 0, hash_enum_size);
     rb_hash_modify_check(hash);
     if (RHASH(hash)->ntbl)
-        rb_hash_foreach(hash, map_v_i, hash);
+        rb_hash_foreach(hash, transform_values_i, hash);
     return hash;
 }
 
@@ -4398,8 +4398,8 @@ Init_Hash(void) https://github.com/ruby/ruby/blob/trunk/hash.c#L4398
     rb_define_method(rb_cHash,"each_pair", rb_hash_each_pair, 0);
     rb_define_method(rb_cHash,"each", rb_hash_each_pair, 0);
 
-    rb_define_method(rb_cHash, "map_v", rb_hash_map_v, 0);
-    rb_define_method(rb_cHash, "map_v!", rb_hash_map_v_bang, 0);
+    rb_define_method(rb_cHash, "transform_values", rb_hash_transform_values, 0);
+    rb_define_method(rb_cHash, "transform_values!", rb_hash_transform_values_bang, 0);
 
     rb_define_method(rb_cHash,"keys", rb_hash_keys, 0);
     rb_define_method(rb_cHash,"values", rb_hash_values, 0);
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 56098)
+++ ChangeLog	(revision 56099)
@@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Sep  8 11:29:00 2016  Kenta Murata  <mrkn@m...>
+
+	* hash.c (rb_hash_transform_values, rb_hash_transform_values_bang):
+	  Rename map_v to transform_values.
+	  [Feature #12512] [ruby-core:76095]
+
+	* test/ruby/test_hash.rb: ditto.
+
 Thu Sep  8 10:08:35 2016  Kazuki Yamaguchi  <k@r...>
 
 	* {ext,test}/openssl: Import Ruby/OpenSSL 2.0.0.beta.2. The full commit
Index: test/ruby/test_hash.rb
===================================================================
--- test/ruby/test_hash.rb	(revision 56098)
+++ test/ruby/test_hash.rb	(revision 56099)
@@ -1415,24 +1415,24 @@ class TestHash < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_hash.rb#L1415
     assert_equal([10, 20, 30], [1, 2, 3].map(&h))
   end
 
-  def test_map_v
+  def test_transform_values
     x = @cls[a: 1, b: 2, c: 3]
-    y = x.map_v {|v| v ** 2 }
+    y = x.transform_values {|v| v ** 2 }
     assert_equal([1, 4, 9], y.values_at(:a, :b, :c))
     assert_not_same(x, y)
 
-    y = x.map_v.with_index {|v, i| "#{v}.#{i}" }
+    y = x.transform_values.with_index {|v, i| "#{v}.#{i}" }
     assert_equal(%w(1.0  2.1  3.2), y.values_at(:a, :b, :c))
   end
 
-  def test_map_v_bang
+  def test_transform_values_bang
     x = @cls[a: 1, b: 2, c: 3]
-    y = x.map_v! {|v| v ** 2 }
+    y = x.transform_values! {|v| v ** 2 }
     assert_equal([1, 4, 9], y.values_at(:a, :b, :c))
     assert_same(x, y)
 
     x = @cls[a: 1, b: 2, c: 3]
-    y = x.map_v!.with_index {|v, i| "#{v}.#{i}" }
+    y = x.transform_values!.with_index {|v, i| "#{v}.#{i}" }
     assert_equal(%w(1.0  2.1  3.2), y.values_at(:a, :b, :c))
   end
 

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

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