mercredi 15 avril 2015

need to use `memoize` in custom module in rails3

I have a module in lib folder. Where I have created a InstanceMethods module.



require 'memoist'
extend Memoist
module MyStudentMethods
def self.included base
base.send :include, InstanceMethods
end

module InstanceMethods
def find_student(user_id)
self.student.find{|student| student.user_id == user_id }
end
memoize :find_student
end
end


I am using this module in my model.



require_dependency 'my_student_methods'

class Student < ActiveRecord::Base
# previously I was using memoize like below commented out code
# require 'memoist'
# extend Memoist
include MyStudentMethods
end


But when I start rails server it through an error:



/home/Projects/school/lib/my_student_methods.rb:12:in `<module:InstanceMethods>': undefined method `memoize' for MyStudentMethods::InstanceMethods:Module (NoMethodError)


Issue: How can I memoize the module method?.


Aucun commentaire:

Enregistrer un commentaire