Earle Clubb wrote:
> I'm trying to find a way to create a copy of a module and then sever all
> ties to the original.  I've tried clone and dup, but if anything (e.g
> class variable) changes in one then it also changes in the other.  The
> result I'm trying to achieve is the same as if I had copied the module
> source code and renamed the module.  Now I have two independent modules
> with identical functionality.  Any ideas on how to do this without
> manually copying code?
> 
> Thanks,
> Earle


module A
end

B = A.clone

A.const_set("MyConstant", 20)
p A.constants
p B.constants
puts A::MyConstant
puts B::MyConstant

--output:--
["MyConstant"]
[]
20
r1test.rb:10: uninitialized constant B::MyConstant (NameError)


new_meth = %q{
  def A.sayhi
    puts 'hi'
  end
}

A.module_eval(new_meth)
A.sayhi
B.sayhi

--output:--
hi
r1test.rb:19: undefined method `sayhi' for B:Module (NoMethodError)
-- 
Posted via http://www.ruby-forum.com/.