-
-
Save eric/1013823 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# A little helper from _why | |
class Object | |
def metaclass | |
class << self; self; end | |
end | |
end | |
module A | |
def self.foo | |
puts "yes" | |
end | |
end | |
module B | |
def foo | |
puts "no" | |
end | |
end | |
A.extend(B) | |
A.foo # => "yes" | |
p A.ancestors # => [A] | |
p A.metaclass.ancestors # => [B, Module, Object, Kernel] | |
p A.instance_methods(false).sort # => [] | |
p A.metaclass.instance_methods(false).sort # => ["<", "<=", "<=>", "==", "===", ">", ">=", "ancestors", "autoload", "autoload?", "class_eval", "class_exec", "class_variable_defined?", "class_variables", "const_defined?", "const_get", "const_missing", "const_set", "constants", "foo", "freeze", "include?", "included_modules", "instance_method", "instance_methods", "method_defined?", "module_eval", "module_exec", "name", "private_class_method", "private_instance_methods", "private_method_defined?", "protected_instance_methods", "protected_method_defined?", "public_class_method", "public_instance_methods", "public_method_defined?", "to_s"] | |
p A.included_modules # => [] | |
p A.metaclass.included_modules # => [B, Kernel] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment