This post originated from an RSS feed registered with Ruby Buzz
by Jay Fields.
Original Post: Rake: Task Overwriting
Feed Title: Jay Fields Thoughts
Feed URL: http://blog.jayfields.com/rss.xml
Feed Description: Thoughts on Software Development
I like this behavior, but sometimes you want to overwrite a task instead of appending to what's already there.
When you no longer want the existing behavior the overwrite method can come in handy.
require'rubygems' require'rake'
classRake::Task defoverwrite(&block) @actions.clear enhance(&block) end end
task :the_taskdo p "one" end
Rake::Task[:the_task].overwrite do p "two" end
Rake::Task[:the_task].invoke # >> "two"
The overwrite method is good, but sometimes you want to redefine the task using one of the specialized Rake tasks. I recently wanted to redefine the test task, so I created the abandon method to remove the existing definition.
Hopefully you wont need this type of thing very often, but it can be handy when you want to overwrite a task that has been previously by a framework you've included.