Reactions to story from Information Corner
Sorting an Array of hashes
http://infostall.wordpress.com/ 2008/ 05/ 13/ sorting-an-array-of-hashes/
We get a situation where we fetch some set of records from db as an array of hashes, and later we need to sort this array based on some field of DB. Here is a very hand code to do so. array_objs =[ {:title => "row1_title" ,:name => "Mumbai"}, {:title => "row2_title" ,:name => "Delhi"}, {:title => "row3_title" ,:name => "Bangalore"} ] array_objs .sort_by {|array_objs| array_objs [:name] }.each do |res| puts “#{res[:name] }” end O/P: Bangalore Delhi Mumbai
More rising blog posts
-
Entertainment »
Mark Strong Joins 'Sherlock Holmes' -- Russell Crowe Still In? -
Business »
No ChaChing For ChaCha Guides -
Lifestyle »
Polly Guerin Talks About Writing Magazine Articles - Videos About Writing -
Politics »
Banning Books...Amazing that this is still a threat in the 21st Century -
Sports »
Beijing Paralympics on YouTube -
Technology »
Legacy Media Underreports Crowds at McCain/Palin Appearances
More rising news stories
-
Entertainment »
Britney 'Getting Opportunity to Start Over' at VMAs -
Business »
Premier League: Chelsea's Deco has said that Robinho signed for Manchester City 'only for the money' -
Lifestyle »
Venezuela to host Russia navy exercise -
Politics »
Civil servants to vote on strike -
Sports »
Football: Manchester United game 'too soon' for Steven Gerrard's Liverpool return
Recent posts from Information Corner
-
Large development@Rails
32 days ago -
Visibility of a method
66 days ago -
Regular expression
66 days ago