Skip to content

Instantly share code, notes, and snippets.

@wilson
Created August 5, 2010 14:28
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 wilson/509804 to your computer and use it in GitHub Desktop.
Save wilson/509804 to your computer and use it in GitHub Desktop.
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