# How to Call function

**URL:** <https://www.ruby-forum.com/t/how-to-call-function/161538>\
**Category:** Rails\
**Created:** [February 27, 2009, 6:21am UTC](https://www.ruby-forum.com/t/how-to-call-function/161538 "2009-02-27T06:21:08Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [February 27, 2009, 6:21am UTC](https://www.ruby-forum.com/t/how-to-call-function/161538/1 "2009-02-27T06:21:08Z")

</div>

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
