how does sort work on hash

Discussion in 'Ruby' started by hemant kumar, Aug 19, 2006.

  1. hemant kumar

    hemant kumar Guest

    I am just a little curious about how exactly sort workes on hashes.

    for example:
    a = {:foo => 10,:bar => 5,:duh => 20}

    a.sort {|x,y| y[1] <=> x[1]}


    now how exactly the above line works.the block is passed two elements at a
    time, as array? If yes, how sort treates the next two elements?

    what algorithm this sort is based on? Is it inplace sorting? or only sort!
    does inplace sorting?

    May be the question is not so much about hashes.
     
    hemant kumar, Aug 19, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Navin
    Replies:
    1
    Views:
    762
    Ken Schaefer
    Sep 9, 2003
  2. rp
    Replies:
    1
    Views:
    582
    red floyd
    Nov 10, 2011
  3. Mmcolli00 Mom
    Replies:
    5
    Views:
    148
    Mmcolli00 Mom
    Jan 12, 2009
  4. Tore Aursand
    Replies:
    3
    Views:
    577
    Anno Siegel
    Sep 16, 2003
  5. Replies:
    1
    Views:
    150
    Xicheng Jia
    Sep 15, 2006
Loading...

Share This Page