草庐IT

SharedVar

全部标签

ruby - 模块的实例变量是否在类与 mixin 之间共享?

我想知道Ruby模块的实例变量在多个类中的行为如何“混合”它。我写了一个示例代码来测试它:#HereisamoduleIcreatedwithoneinstancevariableandtwoinstancemethods.moduleSharedVar@color='red'defchange_color(new_color)@color=new_colorenddefshow_colorputs@colorendendclassExample1includeSharedVardefinitialize(name)@name=nameendendclassExample2includ