same ruby file acting standalone resp. as library

Discussion in 'Ruby' started by Thomas Hafner, Apr 21, 2007.

  1. Hello,

    the class definitions of my ruby file shall always be active, whether
    the file is run as standalone program or whether the file is used
    indirectly by require or load,
    *but* when the file is run standalone, a special piece of code within
    the file shall be active in addition (a kind of main section).

    The idea is that the same ruby code file should be able to act in both
    kinds: as a library and as a standalone program which is using that
    library functionality.

    How can I achieve that easily?

    Regards
    Thomas Hafner
     
    Thomas Hafner, Apr 21, 2007
    #1
    1. Advertising

  2. On Saturday 21 April 2007 16:25, Thomas Hafner wrote:
    > the file is run as standalone program or whether the file is used
    > indirectly by require or load,
    > *but* when the file is run standalone, a special piece of code within
    > the file shall be active in addition (a kind of main section).


    Perhaps you want:

    if __FILE__ == $0
    (do something)
    end

    as was just mentioned in another thread:

    http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/248563


    --
    Jesse Merriman

    http://www.jessemerriman.com/
     
    Jesse Merriman, Apr 21, 2007
    #2
    1. Advertising

  3. Jesse Merriman <> wrote/schrieb <>:

    > Perhaps you want:
    >
    > if __FILE__ == $0
    > (do something)
    > end


    Yes, that's it.

    Thanks
    Thomas
     
    Thomas Hafner, Apr 21, 2007
    #3
    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. Tobias Merler
    Replies:
    0
    Views:
    425
    Tobias Merler
    Oct 9, 2004
  2. Replies:
    1
    Views:
    498
    Sudsy
    Dec 12, 2004
  3. Ulf Meinhardt
    Replies:
    6
    Views:
    2,415
    Arne Vajhøj
    Jan 26, 2008
  4. Manish Buttan

    logging soap req./resp. while invoking webservices

    Manish Buttan, Apr 26, 2004, in forum: ASP .Net Web Services
    Replies:
    9
    Views:
    194
    [MSFT]
    May 6, 2004
  5. JeffP->

    WS Req/Resp as XML

    JeffP->, Sep 29, 2009, in forum: ASP .Net Web Services
    Replies:
    1
    Views:
    710
    JeffP->
    Sep 30, 2009
Loading...

Share This Page