12. What if I only want to print out cheese?


#1

I understand that if I want to list out EVERY ingredient, then the below code works.

s = [["ham", "swiss"], ["turkey", "cheddar"], ["roast beef", "gruyere"]]

s.each do | list |
list.each do | ing |
puts "#{ing}"
end
end

But, what if I only want to print out the cheeses?


#2

@corejumper77999

s = [["ham", "swiss"], ["turkey", "cheddar"], ["roast beef", "gruyere"]]

s.each do | list |
 puts "#{list[1]}"
end

#4

I have experimented with @leonhard.wettengmx.n method and this permitted me to create the tab of 3 rows and 2 columns:

s = [["ham", "swiss"], ["turkey", "cheddar"], ["roast beef", "gruyere"]]
s.each{|x| print "#{x[0]}    #{x[1]}\n"}