我正试图编写一个模块,覆盖类中包含的实例方法。
这不起作用:
require 'active_support'
class Foo
def bar
"bar"
end
end
module NewFoo
extend ActiveSupport::Concern
included do
alias __bar__ bar
end
def bar
"new " + __bar__
end
end
class Baz < Foo
include NewFoo
end
我的期望是
Baz.new.bar.should eql "new bar"
但是我却得到了
undefined local variable or method '__bar__'
错误。
我试过以上的各种方法,包括
def self.include(base)...
无济于事。
有什么线索吗?