From: Ryan Davis Date: 2010-09-11T05:18:40+09:00 Subject: Re: Rake task dependencies question On Sep 10, 2010, at 07:23 , Andrew Wagner wrote: > Quick question about rake task dependencies. Suppose I have the following: > > task :prepare_to_fight => :has_weapons do > ... > end > > task :attack_with_gun => :prepare_to_fight do > ... > end > > task :attack_with_sword => :prepare_to_fight do > ... > end > > Now, by default, if I run "rake attack_with_gun attack_with_sword", it > recognizes that "prepare_to_fight" has already been called when it goes to > run the second task. So it saves itself the trouble and skips it. > > My question is, is there some way to override that? That is, I want to > prepare_to_fight each time, but only define it in one place. Note also that > :prepare_to_fight has a dependency, which I only want to mention in one > place, so I can't just put this in a method. I think it is safe to say that what you've described is NOT a task dependency anymore, and is just a reusable unit of code. In ruby, that's just a method: def prepare_to_fight # ... end task :attack_with_gun do prepare_to_fight end task :attack_with_sword do prepare_to_fight end