Module: Operandi::Utils
- Defined in:
- lib/operandi/utils.rb
Overview
Utility module providing helper methods for the Operandi library
Class Method Summary collapse
-
.deep_dup(object) ⇒ Object
Creates a deep copy of an object to prevent mutation of shared references.
Class Method Details
.deep_dup(object) ⇒ Object
Creates a deep copy of an object to prevent mutation of shared references.
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/operandi/utils.rb', line 25 def deep_dup(object) # Use ActiveSupport's deep_dup if available (preferred for Rails apps) return object.deep_dup if object.respond_to?(:deep_dup) # Fallback to Marshal for objects that support serialization Marshal.load(Marshal.dump(object)) rescue TypeError # Last resort: use dup if available, otherwise return original object.respond_to?(:dup) ? object.dup : object end |