Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails check if IRB console or webpage

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
like image 619
xpepermint Avatar asked Feb 24 '10 21:02

xpepermint


2 Answers

Why not just if defined?(IRB)?

like image 50
indirect Avatar answered Oct 17 '22 17:10

indirect


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.

like image 35
Josh Lindsey Avatar answered Oct 17 '22 19:10

Josh Lindsey