# Run a function as a stand-alone app with arguments

**URL:** <https://www.ruby-forum.com/t/run-a-function-as-a-stand-alone-app-with-arguments/156330>\
**Category:** Ruby\
**Created:** [December 24, 2008, 5:16pm UTC](https://www.ruby-forum.com/t/run-a-function-as-a-stand-alone-app-with-arguments/156330 "2008-12-24T17:16:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nephish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/8e7dd6/32.png) [@nephish](https://www.ruby-forum.com/u/nephish)\
**Post date:** [December 24, 2008, 5:16pm UTC](https://www.ruby-forum.com/t/run-a-function-as-a-stand-alone-app-with-arguments/156330/1 "2008-12-24T17:16:00Z")

</div>

Hey all,

i have a function that needs to be able to be called from within a  
ruby script or run as a stand-alone app from the CLI.

so if i have, for example:

def do\_something(arg1, arg2)  
return arg1 + arg2  
end

in a file called ‘my\_helpers.rb’

how could i set it up to run with a default arg1 and arg2 if not  
provided, be able to run it from the cli, and also be able to run it  
from the script.  
I know these are fundamental kind of questions, but i will stand to  
have a lot of sense made from what i have read in my book.

thanks,  
shawn

---

<div class="post-metadata">

**Author:** ![nephish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/8e7dd6/32.png) [@nephish](https://www.ruby-forum.com/u/nephish)\
**Post date:** [December 24, 2008, 5:23pm UTC](https://www.ruby-forum.com/t/run-a-function-as-a-stand-alone-app-with-arguments/156330/2 "2008-12-24T17:23:36Z")

</div>

shawn bright wrote:

> 

if **FILE** == $0

[http://www.ruby-forum.com/topic/58437](http://www.ruby-forum.com/topic/58437)

---

<div class="post-metadata">

**Author:** ![nephish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/8e7dd6/32.png) [@nephish](https://www.ruby-forum.com/u/nephish)\
**Post date:** [December 24, 2008, 5:37pm UTC](https://www.ruby-forum.com/t/run-a-function-as-a-stand-alone-app-with-arguments/156330/3 "2008-12-24T17:37:40Z")

</div>

Thanks, good link, think i can get everything i need out of there.  
And thanks for rmagick, our company website could not do what we do  
without it.

sk
