Rails checks to see if there is an IRB console or web page

In my model, I would like to check if the application works inside the IRB console or as a website?

class MyModel < ActiveRecord::Base
  def xmethod
    if !isIRBconsol
      self.user_id = UserSession.find.user.id
    end
  end
end
+5
source share
3 answers

This is a bit hacky, but it should work:

class MyModel < ActiveRecord::Base
  def am_i_in_irb?
    self.private_methods.include? 'irb_binding'
  end
end

But, as Katy Van Stone said, this is probably what has the best solution.

+3
source

Why not easy if defined?(IRB)?

+3
source
unless self.private_methods.include? 'irb_binding'
   #put your rufus scheduling here
end
0
source

All Articles