Sha256: 2400b3ba803a717212411bea56fc642737c78a3d2688b6d7b11cd53363f9c844
Contents?: true
Size: 1.16 KB
Versions: 10
Compression:
Stored size: 1.16 KB
Contents
# encoding: utf-8 module IceNine class Freezer # A freezer class for handling Object instances class Object < self # Deep Freeze an object # # @example # object = IceNine.deep_freeze(Object.new) # # @param [Object] object # @param [RecursionGuard] recursion_guard # # @return [Object] def self.guarded_deep_freeze(object, recursion_guard) return object unless object.respond_to?(:freeze) object.freeze freeze_instance_variables(object, recursion_guard) object end # Handle freezing the object's instance variables # # @param [Object] object # @param [RecursionGuard] recursion_guard # # @return [undefined] # # @api private def self.freeze_instance_variables(object, recursion_guard) object.instance_variables.each do |ivar_name| Freezer.guarded_deep_freeze( object.instance_variable_get(ivar_name), recursion_guard ) end end private_class_method :freeze_instance_variables end # Object BasicObject = Object end # Freezer end # IceNine
Version data entries
10 entries across 8 versions & 4 rubygems