Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"require if" in Ruby

Here is what I have in my rack app

#rb file
require 'pry'
class .....

#GemFile
group :development do
    gem "pry"
    gem "pry-nav"
end

Of course, in production it causes an error. How do make a kind of "require if"?

like image 900
Alan Coromano Avatar asked Dec 04 '22 13:12

Alan Coromano


2 Answers

require 'pry' if ENV['RACK_ENV'] == 'development'
like image 90
Eugene Rourke Avatar answered Dec 26 '22 11:12

Eugene Rourke


May be you can embed it inside a if block

according to docs Sinatra provides a environment variable http://www.sinatrarb.com/intro#Environments

if development?
 require 'pry'
end

wherever you need to use it.

this may not be the exact solution you may be looking for just a wild guess

like image 33
Pritesh Jain Avatar answered Dec 26 '22 12:12

Pritesh Jain