[Ruby] hash key order

Yogi yogi.kulkarni at gmail.com
Fri Feb 23 11:17:43 PST 2007


if you do need this behaviour you could use SequencedHash from the
collections gem:
http://www.juretta.com/log/2006/12/29/ruby_sequencedhash/

On 2/23/07, Ryan Davis <ryand-ruby at zenspider.com> wrote:
>
> On Feb 23, 2007, at 1:40 PM, ben wiseley wrote:
>
> > Can you depend on the order of keys in a hash in Ruby?
> >
> > Example:
> > h = {:one => "one", :two => "two"}
> >
> > Will h.keys.first always be :one or can't you depend on that?
>
> Hashes are unordered collections. You can't depend on the order of
> the contents at all.
>
>
> _______________________________________________
> Ruby at zenspider.com - Seattle.rb non-commercial list
> http://www.zenspider.com/seattle.rb
> http://www.zenspider.com/mailman/listinfo/ruby
>


-- 
- Yogi


More information about the Ruby mailing list