I have three rake tasks that modify an instance variable and then call the task :find, This is the Rakefile:
@tags = ['OPTIMIZE', 'TODO', 'FIXME']
task :optimize do
@tags = ['OPTIMIZE']
Rake::Task["find"].invoke
end
task :todo do
@tags = ['TODO']
Rake::Task["find"].invoke
end
task :fixme do
@tags = ['FIXME']
Rake::Task["find"].invoke
end
task :find do
# finds words depending on @tags
end
I would like to remove duplication from the Rakefile and make it more concise. How can I simplify (or combine) the :optimize, :todo, :fixme tasks in this Rakefile?
Rake tasks can take arguments, so instead of relying on an instance variable you can pass the tags in:
and then on the command line:
and then, if you still want named tasks as aliases, passing certain arguments, you can pass them in through
invoke:and calling them: