Created
January 24, 2010 01:36
-
-
Save wycats/284931 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# file1 | |
namespace Yehuda | |
class String | |
def printout | |
puts self | |
end | |
end | |
# file1 after recompilation | |
class String | |
define_method("__ns__::Yehuda::printout") do | |
puts self | |
end | |
end | |
# file2 | |
namespace Rails | |
class String | |
def printout | |
puts "Rails: #{self}" | |
end | |
end | |
# file2 after recompilation | |
class String | |
define_method("__ns__::Rails::printout") do | |
puts "Rails: #{self}" | |
end | |
end | |
# file3 | |
use Yehuda | |
use Rails | |
"Yehuda".printout | |
# file2 after recompilation | |
tmp = "Yehuda" | |
if meth = callsite.get(String, :printout) | |
tmp.send(meth) | |
end | |
if tmp.respond_to?("__ns__::Yehuda::printout") | |
callsite.set(String, :printout, "__ns__::Yehuda::printout") | |
tmp.send("__ns__::Yehuda::printout") | |
elsif tmp.respond_to?("__ns__::Rails::printout") | |
callsite.set(String, :printout, "__ns__::Rails::printout") | |
tmp.send("__ns__::Rails::printout") | |
else | |
callsite.set(String, :printout, "printout") | |
tmp.printout | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment