Ruby Rake Task 的奇怪行为

haohaodehao · January 27, 2025 · Last by msg7086 replied at January 27, 2025 · 205 hits
task :simple_job do
  return 'just end' if true
 // code ...
end

运行代码,然后报错,然后改为 break

task  :simple_job do
  break  if true
 // code ...
end

run 它,依然报错。

一种奇怪的方式来实现提前退出 rake task

task  :simple_job do
  next if true
 // code ...
end

do...end 是一个 block。提早结束 block 就是用 next。 https://stackoverflow.com/a/71075077/29384264

You need to Sign in before reply, if you don't have an account, please Sign up first.