Questions tagged «dup»

6
Ruby的dup和clone方法有什么区别?
在Ruby的文档的dup说: 在一般情况下,clone并dup可能在派生类不同的语义。虽然clone用于复制对象(包括其内部状态),但dup通常使用后代对象的类创建新实例。 但是,当我进行一些测试时,我发现它们实际上是相同的: class Test attr_accessor :x end x = Test.new x.x = 7 y = x.dup z = x.clone y.x => 7 z.x => 7 那么这两种方法有什么区别?
214 ruby  clone  dup 
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.