Topic: Trying to reduce reducency on similar method calls

  files.each do |file_obj|
    file_obj.headers_out.each do |header|
      f.write ",,,,#{header}\n"
    end
    file_obj.ctas_out.each do |cta|
      f.write ",,,,#{cta}\n"
    end
    file_obj.cta_headers_out.each do |cta|
      f.write ",,,,#{cta}\n"
    end
    file_obj.paragraphs_out.each do |p|
      f.write ",,,,#{p}\n"
    end
    file_obj.bullet_headers_out.each do |bh|
      file.write ",,,,#{bh}\n"
    end
    file_obj.bullets_out.each do |bh|
      file.write ",,,,#{bh}\n"
    end
    file_obj.footer_out.each do |f|
      f.write ",,,,#{f}\n"
    end
  end

As you can see i am calling multiple methods from the file_obj, which is my own class, but I am doing the same thing over and over. How can I reduce the redundancy?

Re: Trying to reduce reducency on similar method calls

def file_obj
   my_outs[:headers_out,:ctas_out,...]
   ...
end

files.each do |file_obj|
  file_obj.my_outs.each do |o|
    file_obj.send(o).each do |h|
      f.write(",,,,,#{h}\n")
    end
  end
end

Joe got a job, on the day shift, at the Utility Muffin Research Kitchen, arrogantly twisting the sterile canvas snout of a fully charged icing anointment utensil.

Re: Trying to reduce reducency on similar method calls

Worked like a charm, thankyou.