XML has a concept of document order, but not of attribute order within
one tag.
XML readers are (apparently) not required to remember there order.
Next, the attributes come in a Hash, and this has a BUG (!) which will
be FIXED
(!) in the next Ruby versions. It can’t preserve the order you inserted
its keys.
Until then, your own code must put the keys into the order you need. Try
Next, the attributes come in a Hash, and this has a BUG (!) which will
be FIXED
(!) in the next Ruby versions. It can’t preserve the order you inserted
its keys.
Hmm. A bug is when a language doesn’t operate as described:
p. 46, pickaxe 2:
[a hash’s] elements are not ordered, so you can not easily use a hash as
a stack or a queue.
p. 492
The order in which keys and/or values are returned by the various
iterators over hash contents may seem arbitrary and will generally not
be in insertion order.
$ ri Hash
------------------------------------------------------------ Class: Hash
A +Hash+ is a collection of key-value pairs. It is similar to an
+Array+, except that indexing is done via arbitrary keys of any
object type, not an integer index. The order in which you traverse
a hash by either key or value may seem arbitrary, and will
generally not be in the insertion order.
Hashes have a _default value_ that is returned when accessing keys
that do not exist in the hash. By default, that value is +nil+.
Also, in many other languages dictionaries or associative arrays are
unordered collections.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.