我有以下课程:
module StatCalculators
class Passing
def initialize(user_id, game_id)
@user_id = user_id
@game_id = game_id
end
def save_completion_percentage
completions = StatType.find_by_name("Completions").stats.where(athlete_id: @user_id).sum(:float_value)
attempts = StatType.find_by_name("Pass Attempts").stats.where(athlete_id: @user_id).sum(:float_value)
value = completions/attempts
stat = Stat.new(value: value, game_id: @game_id, athlete_id: @user_id, float_value: value)
stat.save(validate: false)
end
end
end
上面的类有可能需要运行更多的方法,而不必单独调用每个方法……有没有办法在初始化方法中运行所有实例方法?