D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
opt
/
alt
/
ruby34
/
share
/
ri
/
system
/
Array
/
Filename :
to_h-i.ri
back
Copy
U:RDoc::AnyMethod[iI" to_h:ETI"Array#to_h;TF:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph; [I"+Returns a new hash formed from +self+.;To:RDoc::Markup::BlankLine o; ; [I"PWith no block given, each element of +self+ must be a 2-element sub-array; ;TI"@forms each sub-array into a key-value pair in the new hash:;T@o:RDoc::Markup::Verbatim; [I";a = [['foo', 'zero'], ['bar', 'one'], ['baz', 'two']] ;TI"=a.to_h # => {"foo"=>"zero", "bar"=>"one", "baz"=>"two"} ;TI"[].to_h # => {} ;T:@format0o; ; [I"BWith a block given, the block must return a 2-element array; ;TI"2calls the block with each element of +self+; ;TI"Jforms each returned array into a key-value pair in the returned hash:;T@o;; [I",a = ['foo', :bar, 1, [2, 3], {baz: 4}] ;TI"2a.to_h {|element| [element, element.class] } ;TI"T# => {"foo"=>String, :bar=>Symbol, 1=>Integer, [2, 3]=>Array, {:baz=>4}=>Hash} ;T; 0o; ; [I"RRelated: see {Methods for Converting}[rdoc-ref:Array@Methods+for+Converting].;T: @fileI"array.c;T:0@omit_headings_from_table_of_contents_below0I"8to_h -> new_hash to_h {|element| ... } -> new_hash ;T0[ I"();T@%FI" Array;TcRDoc::NormalClass00