I have an AR object called Run that keeps information of when the run was started, ended, disabled, etc. I am trying to create a class Something and want to make it "runnable". So I created a module called Runnable that takes in a run object on initialization. Now say I mix in this module into a class Something. I want the something object to delegate all the methods defined on run to the run object.
module Runnable
def initialize(run)
@run = run
end
def self.method_missing(name, *args)
super unless @run.respond_to?(name)
@run.send(name, args)
end
end
class Something
include Runnable
end
Now if I do:
run = Run.find(123)
run.start_date # works!
something = Something.new(run)
something.start_date # NoMethodError: undefined method `start_date' for #<Something:0x007fb4a276b0c0>
Any idea what I am missing? Is there a better way of doing what I am trying to do?