Ruby module help
In the code below, I am able to call BackgroundJob.starting(job_script)
just fine. However, I keep getting no method error for starting when I try to call JobScriptHelper.starting(RemoveBotReferralCodes)
, for example. The JobScriptHelper
is in the lib folder, while RemoveBotReferralCodes
is in a peer folder called script. Any idea what's going on?
module JobScriptHelper
def starting(job_script)
puts "#{Time.now.strftime('%c')}: #{job_script.name} - starting"
end
end
require 'job_script_helper'
class BackgroundJob < ActiveRecord::Base
extend JobScriptHelper
end
#!/usr/bin/env ruby
require File.expand_path('../../../config/boot', __FILE__)
require File.join(File.expand_path('../../../config/environment', __FILE__))
require 'job_sc开发者_开发知识库ript_helper'
class RemoveBotReferralCodes
def self.remove
# ....
end
end
JobScriptHelper.starting(RemoveBotReferralCodes)
To be able to call JobScriptHelper.starting()
I believe your method definition should be
def JobScriptHelper.starting(job_script)
puts "#{Time.now.strftime('%c')}: #{job_script.name} - starting"
end
精彩评论