Ruby | Array to_h() function Last Updated : 05 Dec, 2019 Comments Improve Suggest changes Like Article Like Report Array#to_h() : to_h() is a Array class method which returns the result of interpreting ary as an array of [key, value] pairs. Syntax: Array.to_h() Parameter: Array Return: the result of interpreting ary as an array of [key, value] pairs. Example #1 : Ruby # Ruby code for to_h() method # declaring array a = [[:foo, :bar], [1, 2]] # to_h method example puts "to_h() method form : #{a.to_h()}\n\n" Output : to_h() method form : {:foo=>:bar, 1=>2} Example #2 : Ruby # Ruby code for to_h() method # declaring array a = [[:geeks, :geeks], [1, 2]] # to_h method example puts "to_h() method form : #{a.to_h{|s| [s.ord, s]}}\n\n" Output : to_h() method form : {:geeks=>:geeks, 1=>2} Comment More infoAdvertise with us Next Article Ruby | Array to_h() function M mayank5326 Follow Improve Article Tags : Ruby Ruby-Methods Ruby Array-class Similar Reads Ruby | Array to_a() function Array#to_a() : to_a() is a Array class method which returns self array. Syntax: Array.to_a() Parameter: Array Return: self array representation Example #1 : Ruby # Ruby code for to_a() method # declaring array a = [18, 22, 33, nil, 5, 6] # declaring array b = [1, 4, 1, 1, 88, 9] # declaring array c 1 min read Ruby | Array to_s() function Array#to_s() : to_s() is a Array class method which returns self array. Syntax: Array.to_s() Parameter: Array Return: self array Example #1 : Ruby # Ruby code for to_s() method # declaring array a = [18, 22, 33, nil, 5, 6] # declaring array b = [1, 4, 1, 1, 88, 9] # declaring array c = [18, 22, 50, 1 min read Ruby | Array to_ary() function Array#to_ary() : to_ary() is a Array class method which returns self array representation. Syntax: Array.to_ary() Parameter: Array Return: self array representation. Example #1 : Ruby # Ruby code for to_ary() method # declaring array a = [18, 22, 33, nil, 5, 6] # declaring array b = [1, 4, 1, 1, 88, 1 min read Ruby | Array push() function Array#push() : push() is a Array class method which appends the given object(s) on to the end of this array. Syntax: Array.push() Parameter: Array Return: appends the given object(s) on to the end of this array. Example #1 : Ruby # Ruby code for push() method # declaring array a = [18, 22, 33, nil, 2 min read Ruby | Array take() function Array#take() : take() is a Array class method which returns the number of elements in the array. Syntax: Array.take() Parameter: Array Return: the number of elements in the array. Example #1 : Ruby # Ruby code for take() method # declaring array a = [18, 22, 33, nil, 5, 6] # declaring array b = [1, 1 min read Like