[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

retrieve ruby script file name

Yuguri Azuma

4/5/2009 2:31:00 AM

Hello Group,

Is there any way to retrieve the file name of the script that you are
executing?
For example if you have a ruby script named kitty.rb :

$./kitty.rb
script name is 'kitty.rb'

Thank you,
--
Posted via http://www.ruby-....

6 Answers

Hugh Evans

4/5/2009 3:02:00 AM

0

Yuguri Azuma wrote:
> Hello Group,
>
> Is there any way to retrieve the file name of the script that you are
> executing?
> For example if you have a ruby script named kitty.rb :
>
> $./kitty.rb
> script name is 'kitty.rb'
>
> Thank you,

puts File.basename(__FILE__)
--
Posted via http://www.ruby-....

Yuguri Azuma

4/5/2009 3:09:00 AM

0

Thanks, Hugh.

Hugh Evans wrote:
> Yuguri Azuma wrote:
>> Hello Group,
>>
>> Is there any way to retrieve the file name of the script that you are
>> executing?
>> For example if you have a ruby script named kitty.rb :
>>
>> $./kitty.rb
>> script name is 'kitty.rb'
>>
>> Thank you,
>
> puts File.basename(__FILE__)

--
Posted via http://www.ruby-....

Robert Klemme

4/5/2009 7:49:00 AM

0

On 05.04.2009 05:01, Hugh Evans wrote:
> Yuguri Azuma wrote:
>> Hello Group,
>>
>> Is there any way to retrieve the file name of the script that you are
>> executing?
>> For example if you have a ruby script named kitty.rb :
>>
>> $./kitty.rb
>> script name is 'kitty.rb'
>>
>> Thank you,
>
> puts File.basename(__FILE__)

Note that there is $0 as well. __FILE__ will contain the name of the
file which contains the currently executed line of code while $0 will
contain the name of the script that the interpreter was started with.
When requiring and loading other files __FILE__ and $0 will point to
different names.

Kind regards

robert

Yuguri Azuma

4/13/2009 9:23:00 AM

0

Hello Robert,

Thank you for the additional information.

Regards,
Yuguri

Robert Klemme wrote:
> On 05.04.2009 05:01, Hugh Evans wrote:
>>> Thank you,
>>
>> puts File.basename(__FILE__)
>
> Note that there is $0 as well. __FILE__ will contain the name of the
> file which contains the currently executed line of code while $0 will
> contain the name of the script that the interpreter was started with.
> When requiring and loading other files __FILE__ and $0 will point to
> different names.
>
> Kind regards
>
> robert

--
Posted via http://www.ruby-....

ext-golla.anil-kumar

4/13/2009 10:16:00 AM

0

Hi,
I want to write a seperated module which contains all common functions in f=
ile say common.rb
And I want to use these functions in my ruby script.
How can I achive these, can anybody help me in this regard.



Thanks,
Anil kumar,=20


lasitha

4/13/2009 12:39:00 PM

0

On Mon, Apr 13, 2009 at 3:45 PM, <ext-golla.anil-kumar@nokia.com> wrote:
> Hi,
> I want to write a seperated module which contains all common functions in file say common.rb
> And I want to use these functions in my ruby script.

Hello Anil, does this help?:
http://...

cheers,
lasitha