From: Peter Pk Date: 2009-01-10T08:52:30+09:00 Subject: Ruby Rake 'advanced' rule arguments Just starting out with Rake and Ruby, and made a little rakefile (below). It does a simple dependency based file copy of source files to a "dist" directory. I works fine, but I was wondering if there is a way to retrieve the "regex" argument to Rake::rule in the proc that generates or modifies the "task_name". If so I wouldn't have to add a variable (testregex in rakefile) in the scope that calls "rule". Or maybe a way to access $' $` and $& from the regex test that matches the rule's target (task_name) If this is better posted to another list let me know ;^> PK # **** rakefile **** task :default => [:test] LIBSRCDIR = '../../common' # I didn't see this in the "FileList" def addprefix(prefix,files) a = FileList.new() # can one allocate to files.size? files.each_index { |i| a[i] = prefix + files[i]; } return(a) end # gotta do what ya gotta do def regexifyPath(str) return(str.gsub(/\//,'\/'). gsub(/\./,'\.')) end # copy in source for AiroNetSampleLib.dll NETLIBSRC = [ 'HTTPClient.cpp', 'HTTPInputStream.cpp', 'HTTPChunkedOutputStream.cpp', 'HTTPClientImpl.h', ] NETLIBDIR = './NetSampleLib' directory NETLIBDIR NETLIBSRC_FULL = addprefix(NETLIBDIR + '/', NETLIBSRC) testregex = Regexp.new('^' + regexifyPath(NETLIBDIR + '/')) rule( testregex => [ proc { |task_name| task_name.sub(testregex, LIBSRCDIR + '/aironet/') } ]) do |t| puts "cp #{t.source} #{t.name}" cp t.source, t.name end task :test => NETLIBSRC_FULL do |t| puts "building #{t.name}" puts "from #{t.prerequisites}" end -- Posted via http://www.ruby-forum.com/.