Sha256: 5b091d9067583f4437effa162a86bd952466d2d03f94d4011965d99daa3b4a92

Contents?: true

Size: 908 Bytes

Versions: 8

Compression:

Stored size: 908 Bytes

Contents

# frozen_string_literal: true

module Anyway
  module Ext
    # Add #deep_freeze to hashes and arrays
    module DeepFreeze
      refine ::Hash do
        def deep_freeze
          freeze
          each_value do |value|
            value.deep_freeze if value.is_a?(::Hash) || value.is_a?(::Array)
          end
        end
      end

      refine ::Array do
        def deep_freeze
          freeze
          each do |value|
            value.deep_freeze if value.is_a?(::Hash) || value.is_a?(::Array)
          end
        end
      end

      if defined?(::ActiveSupport::HashWithIndifferentAccess)
        refine ::ActiveSupport::HashWithIndifferentAccess do
          def deep_freeze
            freeze
            each_value do |value|
              value.deep_freeze if value.is_a?(::Hash) || value.is_a?(::Array)
            end
          end
        end
      end

      using self
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
anyway_config-1.4.4 lib/anyway/ext/deep_freeze.rb
anyway_config-1.4.3 lib/anyway/ext/deep_freeze.rb
anyway_config-1.4.2 lib/anyway/ext/deep_freeze.rb
anyway_config-1.4.1 lib/anyway/ext/deep_freeze.rb
anyway_config-1.4.0 lib/anyway/ext/deep_freeze.rb
anyway_config-1.3.1 lib/anyway/ext/deep_freeze.rb
anyway_config-1.3.0 lib/anyway/ext/deep_freeze.rb
anyway_config-1.2.0 lib/anyway/ext/deep_freeze.rb