Hello everybody!
I have a problem with an Hash of Arrays.
ruby-1.9.2-p136 :001 > x = Hash.new Array.new
=> {}
ruby-1.9.2-p136 :002 > x["test"] << "test"
=> ["test"]
ruby-1.9.2-p136 :003 > x
=> {}
ruby-1.9.2-p136 :004 > x.keys
=> []
ruby-1.9.2-p136 :005 > x["test"]
=> ["test"]
ruby-1.9.2-p136 :006 >
Why is keys empty?
What I am trying to do is build a hash of arrays from an XML file:
b = Hash.new(Array.new)
h = XmlSimple.xml_in self.raw
h["data"][0]["bank"][0]["item"].each do |item|
b[item["cat"]] << item["name"]
end
This is the code, but b has like the test in irb no keys, or seems to
be empty, unless you dont know the key i advance, but that is
impossible, since the item["cat"] is dynamic and it is known of 10
categories at the moment, but it is also known that the number of
categories will go up in the future, so I want to do it future-proof
already today :D
Thank you in Advance
Norbert
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.