Skip to content

Instantly share code, notes, and snippets.

@evanphx
Forked from wycats/thinking.rb
Created January 24, 2010 01:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evanphx/284951 to your computer and use it in GitHub Desktop.
Save evanphx/284951 to your computer and use it in GitHub Desktop.
# file1
namespace Yehuda
class String
def printout
puts self
end
end
# file1 after recompilation
class String
literal[0] = CompiledMethod.new { puts self }
Rubinius.add_method self, :"__ns__::Yehuda::printout", literal[0]
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 tmp.respond_to?("__ns__::Yehuda::printout")
tmp.send("__ns__::Yehuda::printout")
elsif tmp.respond_to?("__ns__::Rails::printout")
tmp.send("__ns__::Rails::printout")
else
tmp.printout
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment