Hint for the day: .keys.sort


(John Carter) #1

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 : john.carter@tait.co.nz
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.