I have the following Struct
Struct.new("TestClient", :loc, :type, :ssh, :hostname, :ip)
@clients = [
Struct::TestClient.new(1, "mac", true, "test1", "192.168.1.101"),
Struct::TestClient.new(1, "mac", true, "test2", "192.168.1.102"),
Struct::TestClient.new(1, "mac", true, "test3", "192.168.1.103"),
Struct::TestClient.new(1, "mac", true, "test4", "192.168.1.104"),
]
...and I can select the IP addresses into an array based on the type in the following way.
@clients.select{|c| c.type == "mac"}.map(&:ip)
=> ["192.168.1.101", "192.168.1.102", "192.168.1.103", "192.168.1.104"]
Can anyone enlighten me what would that obvious way be to select 2 variables from the Struct into a hash. e.g. I want to select all the ip and hostnames into a hash based on the "mac" type.
I'm expecting the result to look something like this:
["192.168.1.101"=>"test1", "192.168.1.102"=>"test2", "192.168.1.103"=>"test3", "192.168.1.104"=>"test4"]
Thank You!