0

I want to overwrite the call method below, by calling an include on the class after it has been defined. Important part is to allow "other" code to abstractly decide which module to include, rather than "opening" the class and using "include"

Example:

module Test1
  def call
    puts "Test1"
  end
end

class MyClass
  def call
    puts "MyClass"
  end
end


MyClass.include(Test1)

x = MyClass.new
x.call

Output:

MyClass

Desired output:

Test1

Tested with Ruby 2.4.3p205

Daniel
  • 7,006
  • 7
  • 43
  • 49
  • Possible duplicate of [Overriding method by another defined in module](https://stackoverflow.com/questions/5944278/overriding-method-by-another-defined-in-module) – infused Feb 27 '19 at 00:25

1 Answers1

0

Ugh... The solution is to use prepend and not include.

MyClass.prepend(Test1)
Daniel
  • 7,006
  • 7
  • 43
  • 49