How to call a rake task programmatically - With arguments

19 views Asked by At

I know we can run a task from within a rakefile like this:

Rake::Task['my_task'].execute()

How to do the same while passing arguments ?

1

There are 1 answers

0
Artur INTECH On

Provided you have the following task:

task :delete_user, [:name] do |t, args|
  puts "#{args.name} is being deleted."
end

You can call it using

Rake::Task['delete_user'].invoke('john')

or

Rake::Task['delete_user'].execute(Rake::TaskArguments.new([:name], ['john']))