I'm looking for a way to advance a set of methods wrapped in a method. Depending on input from users, a certain version of a set of methods needs to be used, but I'm wanting to know how to best version the system. Is there a way I can avoid loads of conditionals and repetitive code?
What I'm currently considering:
module Module_3 def self.alpha() puts 'alpha 3' end end module Module_4 def self.alpha() puts 'alpha 4' end end module Module_5 def self.alpha() puts 'alpha 5' end end version = 4 case version when 3, 6 include Module_3 when 4 include Module_4 else include Module_5 end The issue with this is the method call. I would have to use the module namespace in front:
Module_4.alpha # => alpha 4 So that hard coding means there really is no efficient way around this, that I can find. The case method cannot penetrate a method as the scope keeps it unavailable to any conditional inside the method to make a choice.
module Mod case version # => undefined local variable or method when 3, 6 def self.alpha() puts 'alpha 3' end when 4 def self.alpha() puts 'alpha 4' end else def self.alpha() puts 'alpha 5' end end end include Mod Again, the question: Is there a way I can avoid loads of conditionals and repetitive code?