[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

run a function as a stand-alone app with arguments

shawn bright

12/24/2008 4:07:00 PM

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

2 Answers

Tim Hunter

12/24/2008 4:14:00 PM

0

shawn bright wrote:
> 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
>
>

if __FILE__ == $0

http://www.ruby-forum.com/t...

--
RMagick: http://rmagick.ruby...

shawn bright

12/24/2008 4:28:00 PM

0

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

On Wed, Dec 24, 2008 at 10:14 AM, Tim Hunter <TimHunter@nc.rr.com> wrote:
> shawn bright wrote:
>>
>> 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
>>
>>
>
> if __FILE__ == $0
>
> http://www.ruby-forum.com/t...
>
> --
> RMagick: http://rmagick.ruby...
>
>