简体   繁体   English

如何格式化此哈希?

[英]How do I format this hash?

I have a UUID with three unique properties for each UUID. 我有一个UUID,每个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, 假设我们可以从active_status对象获取名称,状态,pct_complete,

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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