`
ericluo
  • 浏览: 17702 次
最近访客 更多访客>>
社区版块
存档分类
最新评论

Copying an Object

阅读更多

Object#clone, Object#dup都是Ruby中的对象复制的方式,但是这两种方式中都只是浅拷贝(Shallow Copy), 而不是Deep Copy. 那么该如何来做deep_copy呢?Ruby中并没有提供现成的方法来处理。可以用开发者自己来实现对象图Graph中的对象的递归的访问。或者可以采用如下的方法来间接地达到对象拷贝的效果。

<pre>

arr1 = [ 1, "flipper", 3 ]
arr2 = Marshal.load(Marshal.dump(arr1))

</pre>

分享到:
评论

相关推荐

    在JAVA中创建对象.pdf

    Copying an object is a common operation in Java programming, and it can be implemented using the clone() method of the Object class. 在 Java 编程中,创建对象是不可或缺的一步,但是随着程序的复杂度和可...

    Python Cookbook, 2nd Edition

    Copying an Object Recipe 4.2. Constructing Lists with List Comprehensions Recipe 4.3. Returning an Element of a List If It Exists Recipe 4.4. Looping over Items and Their Indices in a Sequence ...

    Packt.Object-Oriented.JavaScript.3rd.Edition

    and make them your own Understand objects in Google Chrome developer tools and how to use Them Use a mix of prototypal inheritance and copying properties in your workflow Apply reactive programming ...

    Object-Oriented Analysis and Design 第六章

    Object Oriented Analysis and Design 11Prototype - MotivationThe Prototype pattern provides a way to create new objects by copying existing ones. It's useful when you want to avoid the overhead of ...

    Object Oriented JavaScript(PACKT,3ed,2017)

    and make them your own Understand objects in Google Chrome developer tools and how to use Them Use a mix of prototypal inheritance and copying properties in your workflow Apply reactive programming ...

    OTA COM Type Library

    When a new entity is created by copying an entity from one Quality Center project to another, dependent entities and dependencies can be optionally copied with the entity. Note that user assets are ...

    CANdb___Manual_EN.pdf

    3.10 Modifying the value of an object's user-defined attribute 27 3.11 Consistency check 28 4 Version administration 29 4.1 Preconditions for version administration capability 30 4.2 Version ...

    Get Programming - Learn to code with Python.epub

    Lesson 31 - Creating a class for an object type Lesson 32 - Working with your own object types Lesson 33 - Customizing classes Lesson 34 - Capstone project: card game UNIT 8 - USING LIBRARIES TO ...

    iphone FastEnumeration

    A real implementation would likely do less work to provide values, such as directly copying object pointers from an internal representation. All code for this sample is in the FastEnumerationSample....

    mastering.java

    First, let me thank you for taking the time to purchase and read my guide, “Mastering Java: An Effective Project-Based Approach including Web Development, Data Structures, GUI Programming and Object ...

    CUDA Reference from NVIDIA official site.

    `cudaEventCreate` creates an event object that can be used for synchronization between the host and device. Events provide a more fine-grained control over synchronization compared to streams and are ...

    Google C++ Style Guide(Google C++编程规范)高清PDF

    Note: If you use a symbol Foo in your source file, you should bring in a definition for Foo yourself, either via an #include or via a forward declaration. Do not depend on the symbol being brought in ...

    falcon SDK

    ("SDK License") is a legal agreement between you (either an individual or a single entity) and Novint Technologies, Inc. (“Novint”) regarding your rights to the Novint SDK (the "SDK"). The SDK ...

    Writing GNOME Applications

    Object Properties Signals GNOME Core Libraries Graphics Libraries Components Gnome-xml 3. The GNOME Build Environment The Configuration Script Running configure Inside the configure Script Makefile ...

    C#入门学习资料001 20190911.rar

    The guide begins by explaining how to install the free Visual Studio Community Edition, which creates an environment where you can quickly build your own executable programs by copying the book’s ...

    Effective C++(第三版)

    don't try to return a reference when you must return an object. 条款22:将成员变量声明为private declare data members private. 条款23:宁以non-member、non-friend替换member函数 prefer non-member non-...

    深入java虚拟机(inside the java virtual machine)

    The Lifetime of an Object Class Instantiation Garbage Collection and Finalization of Objects Unloading and Finalization of Classes On the CD-ROM The Resources Page 8 The Linking Model Dynamic ...

    TMS320F28335资料整理包括技术手册和应用手册+CCS4.2基础实验例程工程文件.zip

    TMS320F28335资料整理包括技术手册和应用手册+CCS4.2基础...spraau8(Copying Compiler Sections From Flash to RAM on the TMS320F28xxx DSCs).pdf spraaw0(Programming External Nonvolatile Memory Using SDFlash for

    Universal-USB-Installer

    Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the ...

Global site tag (gtag.js) - Google Analytics