开发者

Using IRB (i.e. calling 'debugger') with Thor?

I'm trying to get Thor to trigger an IRB prompt when 'debugger' is reached in the code (like Rails, etc). Although I can trigger debugger, how do I get IRB to start automatically when debugger is triggered?

Currently, I do the following in the .thor file:

require 'ruby-debug'

desc 'irb', 'Load IRB console for this app.'
def irb
  puts 'Starting IRB...'
  debugger
end

This results in the debugger being triggered, but IRB must be explicitly started by typing 'irb' at the prompt:

$ thor app
Starting IRB...
(rdb:1) irb
ruby-1.9.2-p180 :001 > puts 'hello'
hello
=> nil
ruby-1.9.2-p180 :002 > exit 
(rdb:1) exit
Really quit? (y/n) y

How do I get IRB to trigger instantly so I don't need to type 'irb开发者_开发知识库' and an extra 'exit'?

Thanks!


For those of you who might have the same question, I did locate two solutions (see http://bashdb.sourceforge.net/ruby-debug.html#Autoirb):


OPTION 1: Set 'autoirb' to on. (my preference)

This is nice because it appears to automatically include your local .irbrc. Downside is you still have to type 'exit' twice if you want to quit the execution of the app (once to exit irb, second to exit debugger).

require 'ruby-debug'
::Debugger.settings[:autoirb] = 1

OPTION 2: Set 'autoeval' to on.

This is nice because it auto-evalutes unknown commands in the debugger and only requires entering 'exit' once to quit, since you are technically still in the debugger console (and not in a nested irb session), and your statements are simply being auto-evaluated. The downside is that your .irbrc settings are ignored. Rails uses this method (more info at: http://www.catapult-creative.com/2009/08/12/make-ruby-debug-work-better/).

require 'ruby-debug'
::Debugger.settings[:autoeval] = 1
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜