Skip to content

Instantly share code, notes, and snippets.

@jaydonnell
Created March 15, 2009 04:31
Show Gist options
  • Save jaydonnell/79305 to your computer and use it in GitHub Desktop.
Save jaydonnell/79305 to your computer and use it in GitHub Desktop.
# "local" methods are those defined directly on a constant,
# as opposed to those inherited or mixed in
class Module
def local_class_methods
self.methods.select { |m| self.method(m).owner == self }
end
def local_instance_methods
self.instance_methods.select { |m| self.instance_method(m).owner == self }
end
end
# 1.8.7 has the owner method already, so just hack one up for 1.8.6
class UnboundMethod
unless defined?(owner)
def owner
x = self.to_s.match( /: ([\w_:]+)(?:\(([\w_:]+)\))?/ )
eval( x[2] || x[1] )
end
end
end
class Method
unless defined?(owner)
def owner
x = self.to_s.match( /: ([\w_:]+)(?:\(([\w_:]+)\))?/ )
eval( x[2] || x[1] )
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment