Sha256: 5f190b779661c86a015f33afbd2366f5c8dea9f594171da55a51ae44ad7c20d6

Contents?: true

Size: 1020 Bytes

Versions: 35

Compression:

Stored size: 1020 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

      begin
        require "active_support/core_ext/hash/indifferent_access"
      rescue LoadError
      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

35 entries across 35 versions & 2 rubygems

Version Path
anyway_config-2.6.4 lib/anyway/ext/deep_freeze.rb
anyway_config-2.6.3 lib/anyway/ext/deep_freeze.rb
anyway_config-2.6.2 lib/anyway/ext/deep_freeze.rb
anyway_config-2.6.1 lib/anyway/ext/deep_freeze.rb
anyway_config-2.6.0 lib/anyway/ext/deep_freeze.rb
runger_config-3.0.1 lib/anyway/ext/deep_freeze.rb
runger_config-3.0.0 lib/anyway/ext/deep_freeze.rb
runger_config-2.7.0 lib/anyway/ext/deep_freeze.rb
runger_config-2.6.1 lib/anyway/ext/deep_freeze.rb
runger_config-2.6.0 lib/anyway/ext/deep_freeze.rb
anyway_config-2.5.4 lib/anyway/ext/deep_freeze.rb
anyway_config-2.5.3 lib/anyway/ext/deep_freeze.rb
anyway_config-2.5.2 lib/anyway/ext/deep_freeze.rb
anyway_config-2.5.1 lib/anyway/ext/deep_freeze.rb
anyway_config-2.5.0 lib/anyway/ext/deep_freeze.rb
anyway_config-2.4.2 lib/anyway/ext/deep_freeze.rb
anyway_config-2.4.1 lib/anyway/ext/deep_freeze.rb
anyway_config-2.4.0 lib/anyway/ext/deep_freeze.rb
anyway_config-2.3.1 lib/anyway/ext/deep_freeze.rb
anyway_config-2.3.0 lib/anyway/ext/deep_freeze.rb