是否有“method_missing"?用于耙任务? [英] Is there a "method_missing" for rake tasks?
问题描述
如果我的 Rakefile 没有找到具有特定名称的任务,我希望 rake
根据某些规则以该名称创建一个新任务,如果缺少任务名称的文件存在.但如果没有,我想退回到默认值(不知道如何构建任务 'foo'!").
If my Rakefile does not find a task with a particular name, I'd like rake
to instead create a new task by that name according to certain rules, if a file with the missing task name exists. But if it doesn't, I want to fall back to the default ("Don't know how to build task 'foo'!").
简而言之,是否有用于 Rake 的 method_missing
?
In short, is there a method_missing
for Rake?
推荐答案
我还没试过,但快速搜索发现 这个.
I haven't tried it, but a quick search revealed this.
如果你定义了一个空的规则字符串,你可以捕捉任何任务其他地方没有定义.这使动态创建变得容易耙任务.本质上,这是method_missing for rake!
If you define a rule with an empty string, you can catch any task that hasn’t been defined elsewhere. This makes it easy to dynamically create rake tasks. Essentially, this is method_missing for rake!
rule "" do |t|
t.name
# ... do something with the name of the task
end
这篇关于是否有“method_missing"?用于耙任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!