>  Q&A  >  본문

ruby - 求教多重 hash 如何取值

求教如何在如下数据中取PublicPort或Image

[#<Docker::Container:0x00000005195578 @id="8aba2f87cdf5e5d340f30fef8e5df8f58d990eab1c70583d4fef3a8fa83de3f2", @info={"Command"=>"/bin/bash", "Created"=>1427722904, "Image"=>"ddddd:latest", "Names"=>["/clever_pike"], "Ports"=>[{"IP"=>"0.0.0.0", "PrivatePort"=>80, "PublicPort"=>10280, "Type"=>"tcp"}], "Status"=>"Up 10 days", "id"=>"8aba2f87cdf5e5d340f30fef8e5df8f58d990eab1c70583d4fef3a8fa83de3f2"}, @connection=#<Docker::Connection:0x00000004aaadf8 @url="unix:///", @options={:socket=>"/var/run/docker.sock"}>>, #<Docker::Container:0x00000005195488 @id="c95642d254f1b716debbc8f5381b1234aff69c92db87a43e9b6f64216d1471b3", @info={"Command"=>"/bin/bash", "Created"=>1427722902, "Image"=>"bbbbbbb:latest", "Names"=>["/serene_heisenberg"], "Ports"=>[{"IP"=>"0.0.0.0", "PrivatePort"=>80, "PublicPort"=>10180, "Type"=>"tcp"}], "Status"=>"Up 10 days", "id"=>"c95642d254f1b716debbc8f5381b1234aff69c92db87a43e9b6f64216d1471b3"}, @connection=#<Docker::Connection:0x00000004aaadf8 @url="unix:///", @options={:socket=>"/var/run/docker.sock"}>>]

以上直接调用docker-api,d=Docker::Container.all获得,相应源代码如下。

rubydef self.all(opts = {}, conn = Docker.connection)
    hashes = Docker::Util.parse_json(conn.get('/containers/json', opts)) || []
    hashes.map { |hash| new(conn, hash) }
end
怪我咯怪我咯2712일 전711

모든 응답(1)나는 대답할 것이다

  • ringa_lee

    ringa_lee2017-04-22 09:02:38

    무슨 말을 하고 싶은지 잘 모르겠지만 해시 값은 매우 간단합니다.

    예를 들어

    으아악

    회신하다
    0
  • 취소회신하다