Alpha Blue wrote:
> Example:
> 
> test = cupcake_report_list
> 
> => {"name"=>"Georgia Tech", "cupcake"=>"Jacksonville St.",
> "conference"=>"ACC", "teamid"=>4, "confid"=>2}
> 
> What I want to do is sort the entire array by the name hash key so that
> if I were to look within the array, it would like so:
> 
> test[0]
> => {"name"=>"Air Force", etc., etc., etc., etc.}
> test[1]
> => {"name"=>"Akron", etc., etc., etc., etc.}
> test[2]
> => {"name"=>"Alabama", etc., etc., etc., etc.}
> 
> etc..
> 
> I can't figure out a way to do that correctly by a specific hash key
> within the array.
> 
> Any ideas on how I can accomplish this?
> 
> Many thanks.

test = [
  {"name"=>"Zakron", "a" => "apple"},
  {"name"=>"Akron",  "a" => "goodbye"},
  {"name"=>"Air Force", "a" => "hello"}
]

result = test.sort_by do |hash|
  hash["name"]
end

p result

--output:--
[{"name"=>"Air Force", "a"=>"hello"}, {"name"=>"Akron", "a"=>"goodbye"}, 
{"name"=>"Zakron", "a"=>"apple"}]

result = test.sort_by do |hash|
  hash["name"]
end

p result

-- 
Posted via http://www.ruby-forum.com/.