module X
end
module Y
end
module Z
#TODO include X replacement of including Y
#TODO include Y replacement of including X
end
有没有办法解决 ruby 不包含 uninclude 关键字的问题??
最佳答案
如果您真的需要这种功能,您可以使用 refinements 来实现.
class Foo
end
module X
def x
puts 'x'
end
end
module Y
end
module R
refine Foo do
include X
include Y
end
end
# In a separate file or class
using R
# Foo now includes X and Y
Foo.new.x
# In a different file or class
# Foo no longer includes X and Y
Foo.new.x # NoMethodError
关于ruby-on-rails - Ruby 2.0 如何在包含模块后从模块中取消包含模块?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19461978/