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

ruby-changes:54296

From: marcandre <ko1@a...>
Date: Sun, 23 Dec 2018 12:43:50 +0900 (JST)
Subject: [ruby-changes:54296] marcandRe: r66505 (trunk): Struct#to_h: Add doc for block form.

marcandre	2018-12-23 12:43:45 +0900 (Sun, 23 Dec 2018)

  New Revision: 66505

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

  Log:
    Struct#to_h: Add doc for block form.
    
    Patch by Shuji Kobayashi [doc] [ci skip] [#15454]

  Modified files:
    trunk/struct.c
Index: struct.c
===================================================================
--- struct.c	(revision 66504)
+++ struct.c	(revision 66505)
@@ -901,13 +901,19 @@ rb_struct_to_a(VALUE s) https://github.com/ruby/ruby/blob/trunk/struct.c#L901
 
 /*
  *  call-seq:
- *     struct.to_h     -> hash
+ *     struct.to_h                        -> hash
+ *     struct.to_h {|name, value| block } -> hash
  *
  *  Returns a Hash containing the names and values for the struct's members.
  *
+ *  If a block is given, the results of the block on each pair of the receiver
+ *  will be used as pairs.
+ *
  *     Customer = Struct.new(:name, :address, :zip)
  *     joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
  *     joe.to_h[:address]   #=> "123 Maple, Anytown NC"
+ *     joe.to_h{|name, value| [name.upcase, value.to_s.upcase]}[:ADDRESS]
+ *                          #=> "123 MAPLE, ANYTOWN NC"
  */
 
 static VALUE

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

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