如何在Ruby中重写这个Hash?[已关闭]

v09wglhw  于 12个月前  发布在  Ruby
关注(0)|答案(1)|浏览(127)

已关闭,此问题需要details or clarity。它目前不接受回答。
**想改善这个问题吗?**通过editing this post添加详细信息并澄清问题。

去年就关门了。
Improve this question

[:sha,"string"]
[:node_id,"dsd"]
[:stats,{:total=>122},:additions=>23],:deletions=>72}]
[:files,[{:sha=>"456"},:filename=>"456"],{:sha=>"123"},:filename=>"123"]]

我想访问sha和stats文件的内容。

client.commit("healtheintent/hcc_reference_service","3a3c56babbc1c77323d178303fa06f8d11e1133d").each do |key,value|

    if("#{key}"=="files")
      puts ("#{value}")
    end
  end

现在,values返回文件中的全部内容。类似地,我如何访问stats

mfpqipee

mfpqipee1#

如何在一般情况下删除哈希

hash = { a: 1, b: 2, c: 2 }

hash.each do |key, value|
  if key == :a
    puts "a is #{value}"
  else
    puts "It is not a, it's #{key}"
  end
end

此外,您还可以使用each_keyeach_value方法仅覆盖键或值

相关问题