zot*_*guy 11 ruby metaprogramming ruby-on-rails
module X
end
module Y
end
module Z
#TODO include X replacement of including Y
#TODO include Y replacement of including X
end
Run Code Online (Sandbox Code Playgroud)
有没有办法解决ruby不包含uninclude关键字的事实?

如果你真的需要这种功能,你可以通过使用改进来实现.
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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2160 次 |
| 最近记录: |