Parsing arrays and searching match on index

I am finding that the following logic works, yet when applied in the
attached file, it fails…

a = [[‘head1’,‘head2’,‘head3’],[‘a’,‘b’,‘c’],[‘x’,‘y’,‘z’]]
puts a.class
headings =a[0]
puts headings.class
b = a
#puts a
b.shift
puts b.class

#puts headings
mark1 = headings.index(“head2”)
puts mark1
mark2 = headings.index(“head3”)
puts mark2
puts “\n*****************”

b.each do |row|
row.each do |elem|
if row.index(elem) == mark1
puts “Selected mark1: #{elem}”
elsif row.index(elem) == mark2
puts "Selected mark2: #{elem} "
else
puts “other”
end
end
end

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs