问题
In my model I would like to check if the app is running inside IRB consol or as a website?
class MyModel < ActiveRecord::Base
def xmethod
if !isIRBconsol
self.user_id = UserSession.find.user.id
end
end
end
回答1:
This is a bit of a hack, but it should work:
class MyModel < ActiveRecord::Base
def am_i_in_irb?
self.private_methods.include? 'irb_binding'
end
end
But as Kathy Van Stone said above, this is probably something that has a better solution.
回答2:
Why not just if defined?(IRB)
?
回答3:
unless self.private_methods.include? 'irb_binding'
#put your rufus scheduling here
end
来源:https://stackoverflow.com/questions/2329729/rails-check-if-irb-console-or-webpage