net-http icon indicating copy to clipboard operation
net-http copied to clipboard

Refining classes in net/http

Open forthrin opened this issue 1 year ago • 1 comments

What is the proper way to refine the initializer of this class? The below does not seem work.

require 'net/http'

module Foo
  refine Gem::Net::HTTPGenericRequest.singleton_class do
    def new(*)
      obj = super
      puts 'IT WORKS!
      obj
    end
  end
end

using Foo

http = Net::HTTP.new('localhost', '8080')
http.send_request('GET', '/')

forthrin avatar Aug 29 '24 17:08 forthrin

@HoneyryderChuck: Do you have a solution here?

forthrin avatar Dec 14 '24 07:12 forthrin

Gem:Net::HTTPGenericRequest is different with Net::HTTPGenericRequest class.

https://github.com/rubygems/rubygems/blob/master/lib/rubygems/vendor/net-http/lib/net/http/generic_request.rb#L11

You shouldn't mix them.

hsbt avatar Jun 11 '25 03:06 hsbt