Friday, February 11, 2011

Re: [Rails] Re: An hash of arrays, how to use?

2011/2/11 Frederick Cheung <frederick.cheung@gmail.com>:
>
>
> On Feb 11, 9:09 pm, Norbert Melzer <timmel...@googlemail.com> 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
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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate