Skip to content

Instantly share code, notes, and snippets.

@tario
Created March 8, 2012 02:32
Show Gist options
  • Save tario/1998165 to your computer and use it in GitHub Desktop.
Save tario/1998165 to your computer and use it in GitHub Desktop.
method_container
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