Sha256: 38dfbb5ccb11639ba6095a4ada9dca4fc87f7ac6b099145d072f03d00c9483d3

Contents?: true

Size: 495 Bytes

Versions: 4

Compression:

Stored size: 495 Bytes

Contents

class Hash
  module DeepFreezable

    def deep_freeze
      each_value { |v| deep_freeze_value v }
      freeze
    end

    def deep_freeze_value(value)
      if value.respond_to? :deep_freeze
        value.deep_freeze
      else
        if value.is_a? Hash
          value.each_value { |v| deep_freeze_value v }
        elsif value.respond_to? :each
          value.each { |v| deep_freeze_value v }
        end
        value.freeze
      end
    end

    private :deep_freeze_value

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
hash_ext-0.6.2 lib/hash_ext/deep_freezable.rb
hash_ext-0.6.1 lib/hash_ext/deep_freezable.rb
hash_ext-0.6.0 lib/hash_ext/deep_freezable.rb
hash_ext-0.5.0 lib/hash_ext/deep_freezable.rb