4 ms·
It's a side effect of their implementation and you should continue to not trust their default ordering.
by bradhe 11y ago
It's a side effect of their implementation and you should continue to not trust their default ordering.
- nvader 11y agoIt appears that since Ruby 1.9 they guarantee insertion order: http://ruby-doc.org/core-2.3.0/Hash.html http://ruby-doc.org/core-2.3.0/Hash.html I guess there are two approaches to solving the problem of people using your data structures the wrong way. Edit: wrong link
- ghayes 11y agoAs opposed to Go [0] > When iterating over a map with a range loop, the iteration order is not specified and is not guaranteed to be the same from one iteration to the next. Since Go 1 the runtime randomizes map iteration order, as programmers relied on the stable iteration order of the previous implementation. [0] https://blog.golang.org/go-maps-in-action https://blog.golang.org/go-maps-in-action
- tom-lord 11y agoYes, you can. Ordering has been guaranteed since ruby v1.9, very much intentionally. The implementation of a ruby hash is now as a doubly linked list [0]. This has inevitably caused a slight performance hit, but the benefits far outweigh the cost IMO. [0] https://www.igvita.com/2009/02/04/ruby-19-internals-ordered-hash/ https://www.igvita.com/2009/02/04/ruby-19-internals-ordered-...