aantix
aantix

Reputation: 499

Ruby gem; type of process that loaded it

I am writing a gem and I have it referenced in the Gemfile. Regardless of whether I call a rake task or start up Webbrick, that gem gets loaded.

I want to detect whether it was loaded from a Rake task or from the web server.

How can my gem detect what type of process loaded the gem?

Upvotes: 4

Views: 53

Answers (1)

Charles Ma
Charles Ma

Reputation: 49151

You can look at $0 and see what "main" file loaded it and figure it out from that. Rake's main file is called "rake", your webserver shouldn't start from the same file.

Upvotes: 2

Related Questions