Skip to content

Instantly share code, notes, and snippets.

@banister
Created December 22, 2010 11:47
Show Gist options
  • Save banister/751422 to your computer and use it in GitHub Desktop.
Save banister/751422 to your computer and use it in GitHub Desktop.
class Hello; end
Hello.singleton_class.class #=> Class
# So methods on Hello.singleton_class should be first looked up as instance methods on Class right?
class Class
def hello
puts "from Class"
end
end
class << Class
def hello
puts "from (Class)"
super
end
end
class << Module
def hello
puts "from (Module)"
super
end
end
class << Object
def hello
puts "from (Object)"
super
end
end
Hello.singleton_class.hello
#=>
from (Class)
from (Module)
from (Object)
from Class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment