2011/2/12 Frederick Cheung <[email protected]>: > > > On Feb 12, 12:47 am, Norbert Melzer <[email protected]> wrote: >> 2011/2/11 Frederick Cheung <[email protected]>:
>> 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 As I mentioned above, my version did it after I introduced "if !b.key? [...]". But I will test the code that botp gave me too, seems to be more DRY :D -- 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.

