Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

130
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda