Forum: Ruby retrieve ruby script file name

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Yuguri A. (Guest)
on 2009-04-05 06:31
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,
Hugh E. (Guest)
on 2009-04-05 07:02
Yuguri A. 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__)
Yuguri A. (Guest)
on 2009-04-05 07:10
Thanks, Hugh.

Hugh E. wrote:
> Yuguri A. 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__)
Robert K. (Guest)
on 2009-04-05 11:52
(Received via mailing list)
On 05.04.2009 05:01, Hugh E. 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
Yuguri A. (Guest)
on 2009-04-13 13:23
Hello Robert,

Thank you for the additional information.

Regards,
Yuguri

Robert K. wrote:
> On 05.04.2009 05:01, Hugh E. 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
unknown (Guest)
on 2009-04-13 14:16
(Received via mailing list)
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.
How can I achive these, can anybody help me in this regard.



Thanks,
Anil kumar,
lasitha (Guest)
on 2009-04-13 16:39
(Received via mailing list)
On Mon, Apr 13, 2009 at 3:45 PM,  <removed_email_address@domain.invalid>
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://is.gd/s8YV

cheers,
lasitha
This topic is locked and can not be replied to.