From: Bertram Scharpf Date: 2009-09-22T01:30:04+09:00 Subject: Re: Hash or array? Hi, Am Dienstag, 22. Sep 2009, 01:05:12 +0900 schrieb Ne Scripter: > I have a question, I want to store some data in two columns, for example > > 0001, stuff1 stuff2 > 0002, morestuff > 0003, extrastuff > 0004, more evenmore > > I initially thought to use a hash, but it scrambles the order of the > data so was unsure of its efficiency and use. Be aware that Array alway assigns all members from [0] to [max]. a = [] a[5] = :five a #=> [nil, nil, nil, nil, nil, :five] To keep the order in Hashes, sort the keys: h = { 1 => :a, 2 => :b } h.keys.sort { |k| h[ k] ... } # or even h.sort.each { |k,v| ... } In Ruby 1.9 the order will be preserved, so just assign ascendingly. Bertram -- Bertram Scharpf Stuttgart, Deutschland/Germany http://www.bertram-scharpf.de