Hint for the day: .keys.sort

Discussion in 'Ruby' started by John Carter, Mar 2, 2004.

  1. John Carter

    John Carter Guest

    I often have cause to refer to .keys of a hash, or .each_pair

    But, unsurprisingly given the nature of a Hash, the values come out in
    random order.

    This means my programs do things in a very different order depending on
    the tiniest change.

    99.9999% of the cases it doesn't matter, but it disturbs my users. For
    user X, things come in this order, for user Y it comes out in a completely
    different order. This makes them worry.

    It really doesn't matter, but it worries them.

    If your user ever possibly sees the output of .keys in any form, get
    into the habit of saying .keys.sort instead.

    It just soothes them and makes your users feel warm and fuzzy.



    John Carter Phone : (64)(3) 358 6639
    Tait Electronics Fax : (64)(3) 359 4632
    PO Box 1645 Christchurch Email :
    New Zealand

    Note to all marketers. If you want to sell things to me, buy Google words.

    I refuse on principle to buy anything sold by spam or popup and I
    never follow any links found in a spam. I do however use Google and
    will often follow the neat non-irritating Google Word ads that are of
    interest to me.
     
    John Carter, Mar 2, 2004
    #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. Andy
    Replies:
    1
    Views:
    736
  2. Replies:
    2
    Views:
    280
  3. Navin
    Replies:
    1
    Views:
    727
    Ken Schaefer
    Sep 9, 2003
  4. John Carter

    Newbie Hint for the day: .keys.sort

    John Carter, Oct 9, 2005, in forum: Ruby
    Replies:
    0
    Views:
    91
    John Carter
    Oct 9, 2005
  5. Rob Redmon

    Convert day of year to month, day

    Rob Redmon, Apr 4, 2008, in forum: Ruby
    Replies:
    7
    Views:
    314
    Alex Wayne
    Apr 4, 2008
Loading...

Share This Page