When you sort a hash with the sort method, you get a multidimensional array of two-element arrays in return. : sort « Hash « Ruby






When you sort a hash with the sort method, you get a multidimensional array of two-element arrays in return.


myHash = { 1 => "One", 2 => "Two", 3 => "Three", 4 =>"Four", 5 => "Five" }
p myHash 

p myHash.sort 

# Hash does not have a sort! method, to change the contents of the hash in place.

 








Related examples in the same category

1.Sort a hash