简体   繁体   中英

How do I format this hash?

I have a UUID with three unique properties for each UUID. I want to store all these. I know I need a hash inside a hash, but I am having trouble doing this.

It's creating them inside a loop, and for each iteration I need to append/add it to the hash, so I'm not sure how to do that either.

19ee480015a2012f0aeb64ce8f2f69f4:
status: complete
name: SaveComment
pct_complete: 100 

083732301597012f0aea64ce8f2f69f4:
status: working
name: SaveComment
pct_complete: 35 

bf40ca301596012f0ae864ce8f2f69f4:
status: complete
name: SaveComment
pct_complete: 100 

This is the code it's going into:

get '/percentcomplete' do
  progress = {}
  Resque::Status.status_ids.each do |uuid|
    active_status = Resque::Status.get(uuid)

    #update hash each loop here with name, status, pct_complete, and uuid
  end
end

Assuming we can get name, status, pct_complete from active_status object,

get '/percentcomplete' do
  progress = {}
  Resque::Status.status_ids.each do |uuid|
    active_status = Resque::Status.get(uuid)

    #update hash each loop here with name, status, pct_complete, and uuid
    progress[uuid.to_s] = {:name => active_status.name, 
            :status => active_status.status, 
            :ptc_complete => active_status.ptc_complete}
  end
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM