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.
B6ab6355f3bc382d2b509e97e0da138a?d=identicon&s=25 Yuguri Azuma (yuguri)
on 2009-04-05 04: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,
441f46313a6f1eae3cdeecc40b1516d0?d=identicon&s=25 Hugh Evans (artpop)
on 2009-04-05 05:02
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__)
B6ab6355f3bc382d2b509e97e0da138a?d=identicon&s=25 Yuguri Azuma (yuguri)
on 2009-04-05 05:10
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__)
E0d864d9677f3c1482a20152b7cac0e2?d=identicon&s=25 Robert Klemme (Guest)
on 2009-04-05 09:52
(Received via mailing list)
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
B6ab6355f3bc382d2b509e97e0da138a?d=identicon&s=25 Yuguri Azuma (yuguri)
on 2009-04-13 11:23
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
688cbfb30e1a2765586c0fd5d97dee95?d=identicon&s=25 unknown (Guest)
on 2009-04-13 12: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,
E16e84e861c1815ce11ba7bd851c857d?d=identicon&s=25 lasitha (Guest)
on 2009-04-13 14:39
(Received via mailing list)
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://is.gd/s8YV

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