Struct#to_h: Add doc for block form.
Patch by Shuji Kobayashi [doc] [ci skip] [#15454] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66505 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
9cc1120424
commit
9777547817
8
struct.c
8
struct.c
@ -901,13 +901,19 @@ rb_struct_to_a(VALUE s)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* 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.
|
* 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)
|
* Customer = Struct.new(:name, :address, :zip)
|
||||||
* joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
|
* joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
|
||||||
* joe.to_h[:address] #=> "123 Maple, Anytown NC"
|
* 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
|
static VALUE
|
||||||
|
Loading…
x
Reference in New Issue
Block a user