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

Version Path
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/ice_nine-0.11.2/lib/ice_nine/freezer/object.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/ice_nine-0.11.2/lib/ice_nine/freezer/object.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/ice_nine-0.11.2/lib/ice_nine/freezer/object.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/ice_nine-0.11.2/lib/ice_nine/freezer/object.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/ice_nine-0.11.2/lib/ice_nine/freezer/object.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/ice_nine-0.11.2/lib/ice_nine/freezer/object.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/ice_nine-0.11.2/lib/ice_nine/freezer/object.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/ice_nine-0.11.2/lib/ice_nine/freezer/object.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/ice_nine-0.11.2/lib/ice_nine/freezer/object.rb
ice_nine-0.11.2 lib/ice_nine/freezer/object.rb