Frank Koehl
Frank Koehl

Reputation: 3176

Check for Rails in gem initialization

I'm building a gem that has some conditional logic on the presence/absence of Ruby on Rails. Some pseudo-code from gem_name/lib/gem_name.rb

# do stuff for all situations

if [Rails is present]
  # do extra rails stuff
end

What's the standard way of performing such a check inside a gem?

Upvotes: 0

Views: 90

Answers (1)

spickermann
spickermann

Reputation: 106802

I would go with:

if defined?(Rails)
  ...
end

Find the documentation for defined? here: http://ruby-doc.org/docs/keywords/1.9/Object.html#method-i-defined-3F

Upvotes: 3

Related Questions