Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
a simple way to debug tons of libs that use ruby's net/http
BEGIN {
require 'net/http'
Net::HTTP.module_eval do
alias_method '__initialize__', 'initialize'
def initialize(*args,&block)
__initialize__(*args, &block)
ensure
@debug_output = $stderr ### if ENV['HTTP_DEBUG']
end
end
}
@myronmarston
Copy link

myronmarston commented Dec 21, 2010

@AndrewVos: the code you've posted overrides Net::HTTP#initialize and supers to the definition of initialize in Net::HTTP's superclass. This means it totally skips Net::HTTP's own definition of initialize. That's not what you want to do :(.

@troelskn
Copy link

troelskn commented Jan 14, 2013

Why module_eval? Isn't this exactly the same, and (imho) much more readable?

module Net
  class HTTP
    alias_method '__initialize__', 'initialize'

    def initialize(*args,&block)
      __initialize__(*args, &block)
    ensure
      @debug_output = $stderr ### if ENV['HTTP_DEBUG']
    end
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment