[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

detect if required or executed?

I. E. Smith-Heisters

6/17/2008 6:00:00 PM

Hi all,

Is anyone aware of a way to detect if a file has been required from
another ruby process, or is being executed from the commandline? I've
been doing this hack:

do_executable_behavior unless ENV['DONT_RUN']

but that's clearly not ideal. I though maybe I could add something to
the bangline? But that wouldn't help if someone runs the script
indirectly with "ruby script.rb". Something like Module.included would
be great if there was a "required" method, I could just set a DONT_RUN
variable there.

Thanks,
Ian
4 Answers

Joel VanderWerf

6/17/2008 6:05:00 PM

0

I. E. Smith-Heisters wrote:
> Hi all,
>
> Is anyone aware of a way to detect if a file has been required from
> another ruby process, or is being executed from the commandline? I've
> been doing this hack:
>
> do_executable_behavior unless ENV['DONT_RUN']
>
> but that's clearly not ideal. I though maybe I could add something to
> the bangline? But that wouldn't help if someone runs the script
> indirectly with "ruby script.rb". Something like Module.included would
> be great if there was a "required" method, I could just set a DONT_RUN
> variable there.
>
> Thanks,
> Ian

There was a good discussion recently about making sure only one instance
of a script is running, maybe that helps:

http://groups.google.com/group/ruby-talk-google/browse_thread/thread/b658d9...


--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

ara.t.howard

6/17/2008 6:07:00 PM

0


On Jun 17, 2008, at 11:59 AM, I. E. Smith-Heisters wrote:

> Is anyone aware of a way to detect if a file has been required from
> another ruby process, or is being executed from the commandline? I've
> been doing this hack:

executed = __FILE__ == $0
required = not executed

a @ http://codeforp...
--
we can deny everything, except that we have the possibility of being
better. simply reflect on that.
h.h. the 14th dalai lama




Joel VanderWerf

6/17/2008 6:16:00 PM

0

Joel VanderWerf wrote:
> There was a good discussion recently about making sure only one instance
> of a script is running, maybe that helps:
>
> http://groups.google.com/group/ruby-talk-google/browse_thread/thread/b658d9...

Oops, I think Ara answered the right question...

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

I. E. Smith-Heisters

6/17/2008 9:30:00 PM

0

On Jun 17, 11:07 am, "ara.t.howard" <ara.t.how...@gmail.com> wrote:
> On Jun 17, 2008, at 11:59 AM, I. E. Smith-Heisters wrote:
>
> > Is anyone aware of a way to detect if a file has been required from
> > another ruby process, or is being executed from the commandline? I've
> > been doing this hack:
>
> executed = __FILE__ == $0
> required = not executed
>
> a @http://codeforp...
> --
> we can deny everything, except that we have the possibility of being  
> better. simply reflect on that.
> h.h. the 14th dalai lama

clever, thanks!