for f in @a
puts f
end
can we write
puts @a.join("\n")
In general, when you want to do something with multiple arrays, you can put the arrays into an array and then use eachfor example.
[@a, @b].each do |list|
list.each { |value| puts value }
end
and as soon as you start doing something more complicated than just printing the values, it makes sense to use refactoring the extraction method when performing the operation, for example.
[@a, @b].each do |list|
do_something_with list
end
, ( " " ..), :
{'As' => @a, 'Bs' => @b}.each_pair do |label, values|
puts "All #{label}"
puts values.join("\n")
end