Created
March 8, 2012 02:32
-
-
Save tario/1998165 to your computer and use it in GitHub Desktop.
method_container
This file contains 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
require "method_source" | |
def method_container_for(target, &blk) | |
# create adhoc class under target | |
method_container = Class.new | |
def method_container.method_added(mname) | |
# do whatever you want with methods (e.g. "use the source" ) | |
p instance_method(mname).source | |
end | |
method_container.class_eval &blk | |
method_container | |
end | |
method_container = method_container_for(Fixnum) do | |
def foo | |
print "hello\n" | |
end | |
end | |
method_container.new.foo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment