Skip to content

Instantly share code, notes, and snippets.

@eric
Forked from dbalatero/wtf.rb
Created June 8, 2011 05:11
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 eric/1013823 to your computer and use it in GitHub Desktop.
Save eric/1013823 to your computer and use it in GitHub Desktop.
# 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