Rails check if IRB console or webpage

白昼怎懂夜的黑 提交于 2019-12-04 07:40:15

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.

Why not just if defined?(IRB)?

unless self.private_methods.include? 'irb_binding'
   #put your rufus scheduling here
end
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!