【发布时间】:2015-09-07 15:37:35
【问题描述】:
我的 rake 文件中有很多实用程序函数,其中一些会创建 rake 任务。我想将这些实用程序函数移动到一个模块中以避免名称冲突,但是当我这样做时,rake 方法不再可用。
require 'rake'
directory 'exampledir1'
module RakeUtilityFunctions
module_function
def createdirtask dirname
directory dirname
end
end
['test1', 'test2', 'test3'].each { |dirname|
RakeUtilityFunctions::createdirtask dirname
}
我得到的错误是:
$ rake
rake aborted!
undefined method `directory' for RakeUtilityFunctions:Module
C:/dev/rakefile.rb:8:in `createdirtask'
C:/dev/rakefile.rb:13:in `block in <top (required)>'
C:/dev/rakefile.rb:12:in `each'
C:/dev/rakefile.rb:12:in `<top (required)>'
据我所知,目录方法由 Rake 中的 following code 放在 ruby 顶层:
# Extend the main object with the DSL commands. This allows top-level
# calls to task, etc. to work from a Rakefile without polluting the
# object inheritance tree.
self.extend Rake::DSL
有没有一种简单的方法来调用像这样放在顶层的函数?
【问题讨论】:
标签: ruby rake rake-task rakefile