我正在嘗試編寫一個rake任務,它將設置鏡像我的項目的環境。如何從rake任務啓動IRB控制檯?
task :environment do
require 'rubygems'
require 'sequel'
# require 'my_projects_special_files'
end
task :foo => [:environment] do
require 'irb'
IRB.start
end
引出IRB抱怨說,「富」不存在(任務名稱)
10:28:01:irb_test >> rake foo --trace (in /Users/mwlang/projects/personal/rake/irb_test) ** Invoke foo (first_time) ** Invoke environment (first_time) ** Execute environment ** Execute foo rake aborted! No such file or directory - foo /opt/local/lib/ruby/1.8/irb/input-method.rb:68:in `initialize' /opt/local/lib/ruby/1.8/irb/input-method.rb:68:in `open' /opt/local/lib/ruby/1.8/irb/input-method.rb:68:in `initialize' /opt/local/lib/ruby/1.8/irb/context.rb:80:in `new' /opt/local/lib/ruby/1.8/irb/context.rb:80:in `initialize' /opt/local/lib/ruby/1.8/irb.rb:92:in `new' /opt/local/lib/ruby/1.8/irb.rb:92:in `initialize' /opt/local/lib/ruby/1.8/irb.rb:57:in `new' /opt/local/lib/ruby/1.8/irb.rb:57:in `start' /Users/mwlang/projects/personal/rake/irb_test/Rakefile:9
確實是這個問題!感謝您的回答 – 2011-08-01 14:42:47
也謝謝! @MichaelLang你應該已經接受了這個答案。 – 2012-03-12 11:18:55
在Ruby 2.4.0中有更直接的方法來做到這一點;看到我的答案。 – 2017-01-12 03:11:19