retrieve ruby script file name

Discussion in 'Ruby' started by Yuguri Azuma, Apr 5, 2009.

  1. Yuguri Azuma

    Yuguri Azuma Guest

    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-forum.com/.
    Yuguri Azuma, Apr 5, 2009
    #1
    1. Advertising

  2. Yuguri Azuma

    Hugh Evans Guest

    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-forum.com/.
    Hugh Evans, Apr 5, 2009
    #2
    1. Advertising

  3. Yuguri Azuma

    Yuguri Azuma Guest

    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-forum.com/.
    Yuguri Azuma, Apr 5, 2009
    #3
  4. 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
    Robert Klemme, Apr 5, 2009
    #4
  5. Yuguri Azuma

    Yuguri Azuma Guest

    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-forum.com/.
    Yuguri Azuma, Apr 13, 2009
    #5
  6. Yuguri Azuma

    Guest

    REG: How can I import a ruby module in my script.

    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
    , Apr 13, 2009
    #6
  7. Yuguri Azuma

    lasitha Guest

    Re: REG: How can I import a ruby module in my script.

    On Mon, Apr 13, 2009 at 3:45 PM, <> 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
    lasitha, Apr 13, 2009
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rob Meade
    Replies:
    1
    Views:
    296
    Rob Meade
    May 22, 2004
  2. =?iso-8859-1?B?bW9vcJk=?=
    Replies:
    7
    Views:
    817
    Roedy Green
    Jan 2, 2006
  3. jacob navia
    Replies:
    38
    Views:
    711
    Mark McIntyre
    Oct 16, 2004
  4. Kiran
    Replies:
    4
    Views:
    174
    Kiran
    Oct 14, 2003
  5. Replies:
    6
    Views:
    161
Loading...

Share This Page