覆盖另一个模块的模块方法

cly*_*yfe 11 ruby

我想覆盖来自另一个模块B的模块A中的方法,该模块将使用猴子补丁A.
http://codepad.org/LPMCuszt

module A
  def foo; puts 'A' end
end

module B
  def foo; puts 'B'; super; end
end

A.module_eval { include B } # why no override ???

class C
  include A
end

# must print 'A B', but only prints 'A' :(
C.new.foo
Run Code Online (Sandbox Code Playgroud)

Vas*_*ich 6

module A
  def foo
    puts 'A'
  end
end

module B
  def foo
    puts 'B'
    super
  end
end

include A # you need to include module A befor you can override method

A.module_eval { include B }

class C
  include A
end

C.new.foo # => B A
Run Code Online (Sandbox Code Playgroud)