Created
August 5, 2010 14:28
-
-
Save wilson/509804 to your computer and use it in GitHub Desktop.
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
def extract_static_instance_method_defs_from(block) | |
klass = Class.new do | |
# swallow any missing class method errors; | |
# we only care to capture the raw method definitions here. | |
def self.method_missing(*a); end | |
# skip any dynamic method definitions | |
def self.define_method(*a); end | |
# run the block so our instance methods get defined | |
class_eval(&block) | |
end | |
instance = klass.new | |
klass.instance_methods(false).inject({}) { |h, m| h[m] = instance.method(m); h } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment