detect if required or executed?

  • Thread starter I. E. Smith-Heisters
  • Start date
I

I. E. Smith-Heisters

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
 
J

Joel VanderWerf

I. E. Smith-Heisters said:
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/b658d9b0dbfd59f8
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top