I'm trying to merge two arrays when there is a key match.
"mac" array should match "id[0]" key, and if match is true append "id[1]" value to my "ip".
For this example will use "computer", "ip address" and "mac address"
id = {
'01:02:03:04:05:06' => 'Desktop'
'07:08:09:10:11:12' => 'Laptop'
}
ip = { '192.168.0.10', '192.168.0.20' }
mac = { '01:02:03:04:05:06', '07:08:09:10:11:12' }
Code I'm using so far;
net = ip.zip(mac)
net.each do |ip,mac|
puts "#{ip} / #{mac}"
end
Example output (wanted):
192.168.0.10 / 01:02:03:04:05:06 / Desktop
192.168.0.20 / 07:08:09:10:11:12 / Laptop
ipandmacare arrays, so enclose with[], not{}(plz edit); 2. it is confusing to give the (local-to-) block variables the same names as the arraysipandmac; 3. you could chain to avoid the need for the temporary variablenet(i.e.,ip.zip(mac).each {|i,m| puts ... }); 4. elements of a hash cannot be identified with indices (id[0]is the value corresponding to key0, ornilif there is no key0), so instead say something like, "for a given elementmofmac, ifidcontains an element with keym, then appendid[m]to...".