D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
opt
/
alt
/
ruby34
/
share
/
ri
/
system
/
Struct
/
Filename :
to_h-i.ri
back
Copy
U:RDoc::AnyMethod[iI" to_h:ETI"Struct#to_h;TF:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph; [I"BReturns a hash containing the name and value for each member:;To:RDoc::Markup::BlankLine o:RDoc::Markup::Verbatim; [ I"2Customer = Struct.new(:name, :address, :zip) ;TI"Ejoe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345) ;TI"h = joe.to_h ;TI"Qh # => {:name=>"Joe Smith", :address=>"123 Maple, Anytown NC", :zip=>12345} ;T:@format0o; ; [I"BIf a block is given, it is called with each name/value pair; ;TI"Jthe block should return a 2-element array whose elements will become ;TI"+a key/value pair in the returned hash:;T@o;; [I"Bh = joe.to_h{|name, value| [name.upcase, value.to_s.upcase]} ;TI"Sh # => {:NAME=>"JOE SMITH", :ADDRESS=>"123 MAPLE, ANYTOWN NC", :ZIP=>"12345"} ;T; 0o; ; [I"FRaises ArgumentError if the block returns an inappropriate value.;T: @fileI" struct.c;T:0@omit_headings_from_table_of_contents_below0I"4to_h -> hash to_h {|name, value| ... } -> hash ;T0[ I"();T@!FI"Struct;TcRDoc::NormalClass00