Sha256: 8ddb5421c0ee5d61f3156d9a1fb22b1d614335db2d894dc8ba9481a6278bd1bb

Contents?: true

Size: 688 Bytes

Versions: 17

Compression:

Stored size: 688 Bytes

Contents

# frozen_string_literal: true

module ActiveResource
  class InheritingHash < Hash
    def initialize(parent_hash = {})
      # Default hash value must be nil, which allows fallback lookup on parent hash
      super(nil)
      @parent_hash = parent_hash
    end

    def [](key)
      super || @parent_hash[key]
    end

    # Merges the flattened parent hash (if it's an InheritingHash)
    # with ourself
    def to_hash
      @parent_hash.to_hash.merge(self)
    end

    # So we can see the merged object in IRB or the Rails console
    def pretty_print(pp)
      pp.pp_hash to_hash
    end

    def inspect
      to_hash.inspect
    end

    def to_s
      inspect
    end
  end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
active_cached_resource-0.1.10 lib/activeresource/lib/active_resource/inheriting_hash.rb
active_cached_resource-0.1.9 lib/activeresource/lib/active_resource/inheriting_hash.rb
active_cached_resource-0.1.8 lib/activeresource/lib/active_resource/inheriting_hash.rb
active_cached_resource-0.1.7 lib/activeresource/lib/active_resource/inheriting_hash.rb
active_cached_resource-0.1.6 lib/activeresource/lib/active_resource/inheriting_hash.rb
active_cached_resource-0.1.5 lib/activeresource/lib/active_resource/inheriting_hash.rb
active_cached_resource-0.1.4 lib/activeresource/lib/active_resource/inheriting_hash.rb
active_cached_resource-0.1.3 lib/activeresource/lib/active_resource/inheriting_hash.rb
active_cached_resource-0.1.2 lib/activeresource/lib/active_resource/inheriting_hash.rb
active_cached_resource-0.1.1 lib/activeresource/lib/active_resource/inheriting_hash.rb
active_cached_resource-0.1.0 lib/activeresource/lib/active_resource/inheriting_hash.rb
active_cached_resource-0.0.1.pre lib/activeresource/lib/active_resource/inheriting_hash.rb
activeresource-6.1.4 lib/active_resource/inheriting_hash.rb
activeresource-6.1.3 lib/active_resource/inheriting_hash.rb
activeresource-6.1.2 lib/active_resource/inheriting_hash.rb
activeresource-6.1.1 lib/active_resource/inheriting_hash.rb
activeresource-6.1.0 lib/active_resource/inheriting_hash.rb