Retrieve ruby script file name

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,

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)

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)

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

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

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,

On Mon, Apr 13, 2009 at 3:45 PM, [email protected]
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?:

cheers,
lasitha

Came here after many years just to find a cleaner way to get filename… But I can only get File.basename($PROGRAM_NAME) or File.basename($0) or File.basename(__FILE__) working … :slight_smile: