我正在尝试编写一个rake任务,该任务将设置一个镜像我的项目的环境。
task :environment do
require 'rubygems'
require 'sequel'
# require 'my_projects_special_files'
end
task :foo => [:environment] do
require 'irb'
IRB.start
end
导致irb抱怨“foo”不存在(任务的名称)
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
答案 0 :(得分:30)
IRB.start正在查看ARGV,其中包含来自rake命令行的任务名称。首先尝试清除ARGV。
require 'irb'
ARGV.clear
IRB.start
答案 1 :(得分:2)
从Ruby 2.4.0开始,你可以这样做:
require 'irb'
binding.irb
答案 2 :(得分:0)
显然,您定义任务的方式一定存在问题。如果你改变
会发生什么task :foo => [:environment] do
到
task :foo => :environment do
答案 3 :(得分:0)
我在运行这样的任务时遇到了类似的问题。将其设置为默认任务解决了问题,但它对bug没有帮助。在这里:我做了什么
task :console do
exec 'irb -I lib -r startingscript.rb'
end
答案 4 :(得分:0)
rake文件内容如下,名为Rakefile 使用rake test:console
从终端运行它require 'rubygems'
require 'rake'
namespace :test do
desc "Test Task"
desc "Load stuff in IRB."
task :console do
exec "irb -r rubygems -r sanitize" #require multiple gems by typing -r gemname
end
end
一旦你执行了rake测试:console,irb弹出,你可以通过使用Sanitize的清洁方法看到它的工作原理。
Sanitize.clean“some text”