Sha256: 4c6529d755a7696c52e40ce236955836cad1d08082e0ada0a538e1f1a9483b4d

Contents?: true

Size: 771 Bytes

Versions: 37

Compression:

Stored size: 771 Bytes

Contents

# frozen_string_literal: true

module Plutonium
  module Lib
    class DeepFreezer
      def self.freeze(object)
        #  Recursive calling #deep_freeze for enumerable objects.
        if object.respond_to? :each
          if object.instance_of?(Hash)
            object.each { |key, val| freeze(val) }
          else
            object.each { |val| freeze(val) }
          end
        end

        # #  Freezing of all instance variable values.
        # object.instance_variables.each do |var|
        #   frozen_val = instance_variable_get(var)
        #   frozen_val.deep_freeze
        #   instance_variable_set(var, frozen_val)
        # end

        if object.frozen?
          object
        else
          object.freeze
        end
      end
    end
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
plutonium-0.19.2 lib/plutonium/lib/deep_freezer.rb
plutonium-0.19.1 lib/plutonium/lib/deep_freezer.rb
plutonium-0.19.0 lib/plutonium/lib/deep_freezer.rb
plutonium-0.18.8 lib/plutonium/lib/deep_freezer.rb
plutonium-0.18.7 lib/plutonium/lib/deep_freezer.rb
plutonium-0.18.6 lib/plutonium/lib/deep_freezer.rb
plutonium-0.18.5 lib/plutonium/lib/deep_freezer.rb
plutonium-0.18.4 lib/plutonium/lib/deep_freezer.rb
plutonium-0.18.3 lib/plutonium/lib/deep_freezer.rb
plutonium-0.18.2 lib/plutonium/lib/deep_freezer.rb
plutonium-0.18.1 lib/plutonium/lib/deep_freezer.rb
plutonium-0.18.0 lib/plutonium/lib/deep_freezer.rb
plutonium-0.16.5 lib/plutonium/lib/deep_freezer.rb
plutonium-0.16.4 lib/plutonium/lib/deep_freezer.rb
plutonium-0.16.3 lib/plutonium/lib/deep_freezer.rb
plutonium-0.16.1 lib/plutonium/lib/deep_freezer.rb
plutonium-0.16.0 lib/plutonium/lib/deep_freezer.rb
plutonium-0.15.24 lib/plutonium/lib/deep_freezer.rb
plutonium-0.15.23 lib/plutonium/lib/deep_freezer.rb
plutonium-0.15.22 lib/plutonium/lib/deep_freezer.rb