The point here is to browse the array docfiles and return two arrays (temporary_file_paths and temporary_file_names).
I decided to return a Hash, but I feel I could get rid of the 2 temporary arrays but I’m not sure how…
def self.foobar docfiles
temporary_information = Hash.new
temporary_file_paths = []
temporary_file_names = []
docfiles.each do |docfile|
if File.exist? docfile.path
temporary_file_paths << "new_path"
temporary_file_names << "something_else"
end
end
temporary_information[:file_paths] = temporary_file_paths
temporary_information[:file_names] = temporary_file_names
return temporary_information
end
There are tons of solutions here.
Returning a double value.
Using collect.
Using inject (if you want a hash)
All the solutions above don’t change the main method logic.
I don’t like very much using arrays/hashes instead of objects so I usually end up converting hashes in objects when the execution requires multiple elaborations.
Also, I don’t know the meaning of
somethingelse but if it’s something you can get from the new_path, then you can use lazy execution.