From: matz@... (Yukihiro Matsumoto) Date: 2002-01-08T11:16:45+09:00 Subject: Re: OT: Re: Sorting a Hash by value of integer stored in the Hash Hi, In message "[ruby-talk:30336] OT: Re: Sorting a Hash by value of integer stored in the Hash" on 02/01/06, Michal Rokos writes: |Yohanes Santoso wrote: |> irb(main):011:0> myh = {"z"=>5,"x"=>3,"y"=>7} |> irb(main):012:0> myh.sort{|a,b| a[1] <=> b[1]} |> ary = [["x", 3], ["z", 5], ["y", 7]] | ^^^^^^^ | Is there any "automatic" way to create hash from ary (above). I | didn't find any. (I know hash = Hash[[1,2,3,4]], but I doesn't | work for this) If you're using 1.7.x ary = [["x", 3], ["z", 5], ["y", 7]] ary.inject({}){|h,(k,v)| h[k]=v; h}' otherwise see page 45 of the pixaxe book. matz.