Created
July 25, 2009 05:37
-
-
Save listrophy/154710 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
module Submethods | |
def self.included(base) | |
base.extend ClassMethods | |
end | |
module ClassMethods | |
def submethods type = :public | |
if self.class.name == "Object" | |
return nil | |
end | |
parent = self.superclass | |
methods = case type | |
when :public, :pub, :pu | |
self.public_methods - parent.public_methods | |
when :private, :priv, :pri | |
self.private_methods - parent.private_methods | |
when :protected, :protect, :pro | |
self.protected_methods - parent.protected_methods | |
when :inst_public, :inst_pub, :inst_pu, :public_inst, :pub_inst, :pu_inst | |
self.public_instance_methods - parent.public_instance_methods | |
when :inst_private, :inst_priv, :inst_pri, :private_inst, :priv_inst, :pri_inst | |
self.private_instance_methods - parent.private_instance_methods | |
when :inst_protected, :inst_protect, :inst_pro, :protected_inst, :protect_inst, :pro_inst | |
self.protected_instance_methods - parent.protected_instance_methods | |
else | |
raise "Unknown method type #{type.to_s}" | |
end | |
puts methods.sort.join("\n") | |
nil | |
end | |
end | |
end | |
class Object | |
include Submethods | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment