Question

As you can see, I've defined a function inside a rake file. No problem, that works fine. Problem is, when I declare def get_user_input in another rake file. In that case the function gets called from another .rake file Can you suggest anything? Thanks.

namespace :backtest do

  def get_user_input
    if ENV['date_from'].present? && ENV['date_until'].present? 
      # get input...
    else
      abort 'Sample usage: blah blah...'
    end
  end

  desc "Start backtest"
  task :start => :environment do
    get_user_input
    # rest of the code...
  end
end
Was it helpful?

Solution 2

Moved the functions into a module and the problem gone.

namespace :backtest do

 Module MY
  def self.get_user_input
    if ENV['date_from'].present? && ENV['date_until'].present? 
      # get input...
    else
      abort 'Sample usage: blah blah...'
    end
  end
 end

 desc "Start backtest"
 task :start => :environment do
   My.get_user_input
   # rest of the code...
 end

end

OTHER TIPS

you can do this:

require 'rake'
load 'your_rake_file_name_here.rake'
get_user_input
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top