Sha256: 38c36c7f3c65d4abcb3e8e3c5e4cf68329ee663c0fded6b4e47675b818a2f473

Contents?: true

Size: 843 Bytes

Versions: 21

Compression:

Stored size: 843 Bytes

Contents

# frozen_string_literal: true

module Appydave
  module Tools
    module Types
      # Hash with indifferent access
      class IndifferentAccessHash < Hash
        def initialize(initial_hash = {})
          super()
          update(initial_hash)
        end

        def [](key)
          super(convert_key(key))
        end

        def []=(key, value)
          super(convert_key(key), value)
        end

        def fetch(key, *args)
          super(convert_key(key), *args)
        end

        def delete(key)
          super(convert_key(key))
        end

        private

        def convert_key(key)
          key.is_a?(Symbol) ? key.to_s : key
        end

        def update(initial_hash)
          initial_hash.each do |key, value|
            self[convert_key(key)] = value
          end
        end
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
appydave-tools-0.13.0 lib/appydave/tools/types/indifferent_access_hash.rb
appydave-tools-0.12.0 lib/appydave/tools/types/indifferent_access_hash.rb
appydave-tools-0.11.11 lib/appydave/tools/types/indifferent_access_hash.rb
appydave-tools-0.11.10 lib/appydave/tools/types/indifferent_access_hash.rb
appydave-tools-0.11.9 lib/appydave/tools/types/indifferent_access_hash.rb
appydave-tools-0.11.8 lib/appydave/tools/types/indifferent_access_hash.rb
appydave-tools-0.11.7 lib/appydave/tools/types/indifferent_access_hash.rb
appydave-tools-0.11.6 lib/appydave/tools/types/indifferent_access_hash.rb
appydave-tools-0.11.5 lib/appydave/tools/types/indifferent_access_hash.rb
appydave-tools-0.11.4 lib/appydave/tools/types/indifferent_access_hash.rb
appydave-tools-0.11.3 lib/appydave/tools/types/indifferent_access_hash.rb
appydave-tools-0.11.2 lib/appydave/tools/types/indifferent_access_hash.rb
appydave-tools-0.11.1 lib/appydave/tools/types/indifferent_access_hash.rb
appydave-tools-0.11.0 lib/appydave/tools/types/indifferent_access_hash.rb
appydave-tools-0.10.4 lib/appydave/tools/types/indifferent_access_hash.rb
appydave-tools-0.10.3 lib/appydave/tools/types/indifferent_access_hash.rb
appydave-tools-0.10.2 lib/appydave/tools/types/indifferent_access_hash.rb
appydave-tools-0.10.1 lib/appydave/tools/types/indifferent_access_hash.rb
appydave-tools-0.10.0 lib/appydave/tools/types/indifferent_access_hash.rb
appydave-tools-0.9.5 lib/appydave/tools/types/indifferent_access_hash.rb