I am trying to understand this code snippet:
while row = input.gets
row.strip!
next if row.empty?
valuesplit = row.split("---")
a, b = valuesplit[1..2]
unless a == b
$hash1[a] ||= {} <--------------What is this line doing? How is the whole loop
$hash1[a][b] = true being traversed?
if $hash1[b] && $hash1[b][a] <-----Can you please describe this if() loop
$hash2[a] ||= []
$hash2[a] << b
$hash2[b] ||= []
$hash2[b] << a
end
end
end
NOTE: $hash1 = {}
$hash2 = {}
Thanks!
UPDATE
Input:
junkdata1 value1 value2
junkdata2 value3 value4
junkdata3 value5 value6
and so on.
Updated the code lines with comments too.
1 Answer