How to Call function

if sub.include?(“html”)
path = File.join("/ACMServer_exe/ChatHistory",f,sub_folder_name,sub)
@file_path << path
@found_folder << sub_folder_name
@chat_date << f
end

The above code has to be used in my controller repeatively in the same
function.
like below
if something
if sub.include?(“html”)
path = File.join("/ACMServer_exe/ChatHistory",f,sub_folder_name,sub)
@file_path << path
@found_folder << sub_folder_name
@chat_date << f
end
elsif
if sub.include?(“html”)
path = File.join("/ACMServer_exe/ChatHistory",f,sub_folder_name,sub)
@file_path << path
@found_folder << sub_folder_name
@chat_date << f
end
else
if sub.include?(“html”)
path = File.join("/ACMServer_exe/ChatHistory",f,sub_folder_name,sub)
@file_path << path
@found_folder << sub_folder_name
@chat_date << f
end
end

Because Parameter will be changing.
i want to reduce my legth of code.
pls help how to make those code into function.
and how can i call that function in to my controller.
i dont have any idea how that function can return the output to my
controoler function .

Kinldy help me to learn .
Thanks