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