I have an instance of a master class that generates instances of a subclass, these subclasses should redirect some method calls back to the main instance.
At the moment, I have code that looks something like this, but it seems to me that I could do the same thing more efficiently (perhaps using the method_missing method?)
class Master def initalize(mynum) @mynum = mynum end def one_thing(subinstance) "One thing with #{subinstance.var} from #{@mynum}" end def four_things(subinstance) "Four things with #{subinstance.var} from #{@mynum}" end def many_things(times,subinstance) "#{times} things with #{subinstance.var} from #{@mynum}" end def make_a_sub(uniqueness) Subthing.new(uniqueness,self) end class Subthing def initialize(uniqueness,master) @u = uniqueness @master = master end
I hope you see what happens here. I would use the method_missing method, but I'm not sure how to deal with the possibility of some calls with arguments and some not (I canβt even reorder the order of the arguments for the Master methods)
Thank you for reading!
source share