Module: Strava::DeepCopyable
- Included in:
- Api::Pagination, Web::Response
- Defined in:
- lib/strava/deep_copyable.rb
Overview
Mixin module for deep copying objects.
This module provides a helper method for creating deep copies of objects using Ruby's Marshal serialization. Unlike shallow cloning (which only duplicates the top-level object), deep copying recursively duplicates all nested objects and collections.
This is particularly useful when working with model objects that contain nested hashes or arrays, ensuring modifications to the copy don't affect the original object.
Instance Method Summary collapse
-
#deep_copy(obj) ⇒ Object
Ruby's way of creating a true deep copy/clone.
Instance Method Details
#deep_copy(obj) ⇒ Object
Ruby's way of creating a true deep copy/clone.
31 32 33 |
# File 'lib/strava/deep_copyable.rb', line 31 def deep_copy(obj) Marshal.load(Marshal.dump(obj)) end |