Home > Mobile >  Using method within rake file tasks
Using method within rake file tasks

Time:10-15

A set of rake tasks of a .rake file are structured as follows

task :process_data  => :environment do
  CSV.foreach("scores.tsv", :col_sep => "\t", headers: true) do |row|
    begin
      [...]
       repeated_method_a
       ad-hoc_method
       repeated_method_b
    rescue StandardError => e
    end
  end
end

How should this rake file be structured to process sub-methods, such as:

def repeated_method_a
  do_its_thing
end

CodePudding user response:

You can simply add it under your task in the same file, so you have this:

task :process_data  => :environment do
  CSV.foreach("scores.tsv", :col_sep => "\t", headers: true) do |row|
    begin
      [...]
       repeated_method_a
       ad-hoc_method
       repeated_method_b
    rescue StandardError => e
    end
  end
end

def repeated_method_a
  do_its_thing
end
  • Related