Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can a Ruby class detect the process name that runs it?

I am using delayed_jobs to run Ruby classes, how can the Ruby detect the name (command) of the process that is running it?

any thoughts?

like image 420
Ran Avatar asked Oct 11 '22 22:10

Ran


2 Answers

You can determine the name of the file using $0. You can even set the process name using it like so $0 = 'foo'Dave Thomas's blog post. If you want to get the command line args, you want to look at ARGV.

like image 172
BaroqueBobcat Avatar answered Oct 21 '22 02:10

BaroqueBobcat


$0 Contains the name of the script being executed. (May be assignable so it can go wrong)

like image 2
eloyesp Avatar answered Oct 21 '22 01:10

eloyesp