On Feb 12, 12:47 am, Norbert Melzer <[email protected]> wrote: > 2011/2/11 Frederick Cheung <[email protected]>: > > > > > On Feb 11, 9:09 pm, Norbert Melzer <[email protected]> wrote: > >> Why is keys empty? > > > because you've never actually done x["test"]= ... > > (all you're doing is modifying the hash's default value) > > OK, now I tried the following > > b = Hash.new(Array.new) > h = XmlSimple.xml_in self.raw > > h["data"][0]["bank"][0]["item"].each do |item| > if b.key? item["cat"] > b[item["cat"]] = item > else > b[item["cat"]] << item
You're still essentially committing the same error - you're only setting b[item['cat'] if there is already an entry for b[item['cat']] Did you really mean to use a hash with a single array as its default value? (The default value stuff doesn't seem to be helping you at all, just muddying the waters Fred > end > end > > pp b.keys > > but b.keys is still empty... -- 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.

