module CoreExtensions
  module Hash
    # hard to debug hash lookup, so here are some expectations
    def lookup(*keys)
      result = keys.inject(self) do |memo, key|
        fail KeyError, "key #{key} must be applied to ahash!" unless memo.is_a? Hash
        new_hash = memo[key]
        fail KeyError, "key #{key} returning nil!" unless new_hash
        new_hash
      end
      copy = Marshal.dump(result)
      Marshal.load(copy)
    end
  end
end
