Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > same ruby file acting standalone resp. as library

Reply
Thread Tools

same ruby file acting standalone resp. as library

 
 
Thomas Hafner
Guest
Posts: n/a
 
      04-21-2007
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
 
Reply With Quote
 
 
 
 
Jesse Merriman
Guest
Posts: n/a
 
      04-21-2007
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...by-talk/248563


--
Jesse Merriman
http://www.velocityreviews.com/forums/(E-Mail Removed)
http://www.jessemerriman.com/

 
Reply With Quote
 
 
 
 
Thomas Hafner
Guest
Posts: n/a
 
      04-21-2007
Jesse Merriman <(E-Mail Removed)> wrote/schrieb <(E-Mail Removed)>:

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


Yes, that's it.

Thanks
Thomas
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hosts file acting up? Penang Computer Support 16 11-02-2008 08:56 AM
Help ruby started acting strange Ion Frantzis Ruby 8 11-07-2006 10:23 AM
Cross-platform standalone Ruby apps ? Pieter Kubben Ruby 13 09-12-2006 03:48 AM
standalone xml library? Noah Roberts C++ 6 03-25-2005 01:45 PM
Any problems with writing the information into a file - Multi-users perform writing the same file at the same time ???? HNguyen ASP .Net 4 12-21-2004 01:53 PM



Advertisments