J
Jean-nicolas Jolivet
I was wondering if the hash.each_pair function messes with the order of
my hash?
I am using it to parse some text and replace html entities and
apparently it changes the order of my hash before iterating each
pairs...
Here is some example code to explain what I mean:
rep = {
"&" => """,
"<" => "<"
...
}
rep.each_pair do |key, value|
text.gsub(key, value)
end
Now obviously, the substitution needs to be done in the correct order
(i.e. & needs to be parsed before <...)
But somehow, each_pair changes the order of my hash before executing the
do block, so things arent getting parsed in the correct order...
Any ideas as to why the hash seems to be re-ordered before the do block
is executed, and how I can prevent this??
my hash?
I am using it to parse some text and replace html entities and
apparently it changes the order of my hash before iterating each
pairs...
Here is some example code to explain what I mean:
rep = {
"&" => """,
"<" => "<"
...
}
rep.each_pair do |key, value|
text.gsub(key, value)
end
Now obviously, the substitution needs to be done in the correct order
(i.e. & needs to be parsed before <...)
But somehow, each_pair changes the order of my hash before executing the
do block, so things arent getting parsed in the correct order...
Any ideas as to why the hash seems to be re-ordered before the do block
is executed, and how I can prevent this??