How do I pass arguments from the parent task to the child task in Rake?

前端 未结 2 889
盖世英雄少女心
盖世英雄少女心 2021-02-02 00:15

I am writing a Rake script which consists of tasks with arguments. I figured out how to pass arguments and how to make a task dependent on other tasks.

task :pa         


        
2条回答
  •  时光取名叫无心
    2021-02-02 00:53

    Setting attributes seems to work like a charm too.

    Just ensure the the task dependency is set to the task that sets the attributes you need.

    # set the attribute I want to use in another task
    task :buy_puppy, [:name] do |_, args|
      name = args[:name] || 'Rover'
      @dog = Dog.new(name)
    end
    
    # task I actually want to run
    task :walk_dog => :buy_puppy do
      @dog.walk
    end
    

提交回复
热议问题