Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

133
Visualizações
Sorbet overrides URI from Kernel

I have method as below

  sig do
    params(uri: URI).returns(String)
  end
  def get(uri)
    http = Net::HTTP.new(uri.host, uri.port)
    http.use_ssl = true
    http.start
    response = http.request_get(uri.path)
    response.body
  ensure
    http&.finish
  end

Test method is like below (does not use sorbet)

def test_get_retry
    uri = URI('http://localhost:4567')
    instance = BookStoreHttpClient.new
    begin
      instance.get_with_retry(uri)
    rescue StandardError
      assert(true)
    end
end

But Sorbet complains with "Method host does not exist on URI", but it is a Kernel class actually.

Is there a way to tell Sorbet to use Kernel::URI instead of URI in sorbet/rbi/hidden-definitions/hidden.rbi

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Sorbet is correct, and the problem is not that it's using the wrong URI.

URI is not a type, it's a module that contains types: URI::Generic, URI::HTTPS etc. Kernel::URI is also not a type, it's a function that returns an instance of one of the types contained in the URI module.

For example:

URI("google.com") # => #<URI::Generic google.com>
URI("https://www.google.com") # => #<URI::HTTPS https://www.google.com>

You should either specify the type of URI you want, for example:

params(uri: URI::HTTPS).returns(String)

Or pick a subset and use a union type:

params(uri: T.any(URI::HTTP, URI::HTTPS)).returns(String)
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda