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 | |
} |
This comment has been minimized.
This comment has been minimized.
drogus
commented
Dec 13, 2010
AndrewVos: no, cause he is changing class definition. He could call super if he would create a new class:
|
This comment has been minimized.
This comment has been minimized.
AndrewVos
commented
Dec 13, 2010
Interesting. First time I've seen BEGIN before, and googling it was kind of tricky :) (did get it eventually though). |
This comment has been minimized.
This comment has been minimized.
AndrewVos
commented
Dec 18, 2010
Ok. I actually thought that super would call the same method on the parent class! I expected this kind of thing to work:
|
This comment has been minimized.
This comment has been minimized.
drogus
commented
Dec 18, 2010
AndrewVos: you're right, super will call method from parent class. But in that gist inheritance is not used, class is evaled. |
This comment has been minimized.
This comment has been minimized.
AndrewVos
commented
Dec 18, 2010
Ok I get it I think. why couldn't it be written like this though? require 'net/http'
Is it because Net:HTTP is actually a module and not a class? |
This comment has been minimized.
This comment has been minimized.
myronmarston
commented
Dec 21, 2010
@AndrewVos: the code you've posted overrides |
This comment has been minimized.
This comment has been minimized.
troelskn
commented
Jan 14, 2013
Why
|
This comment has been minimized.
AndrewVos commentedDec 12, 2010
Couldn't you remove line 6 and replace line 9 with "super"?