From: 7stud -- Date: 2008-03-07T01:17:06+09:00 Subject: Re: Cloning a module and isolating it from the clone 7stud -- wrote: > > I see now why that doesn't work. Even though the code changes the class > variables in B at the module scope, inside B's methods the class > variables still refer to the same objects in A. This demonstrates that: > > > test = %q{ > def B.get_my_num > @@num #this is the @@num in B at module scope that was erased and > replaced > end > } > > A.set_num(35.2) > B.module_eval(test) > puts B.get_num #retrieves the @@num inside get_num which is still a > reference to objects in A > puts B.get_my_num > > --output:-- > 35.2 > 0 Or, maybe what is really happening is that module B has references to the methods in module A. So, when you call B.get_num, you are really calling A.get_num, which then returns A's class variable @@num. -- Posted via http://www.ruby-forum.com/.