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”
ruby-1.9.2-p136 :003 > x
ruby-1.9.2-p136 :004 > x.keys
ruby-1.9.2-p136 :005 > x[“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"]["bank"]["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
Thank you in Advance