Created
August 22, 2011 19:59
-
-
Save luke-gru/1163364 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
#!/usr/bin/env ruby | |
class Parent | |
class << self | |
def greet | |
"singleton parent" | |
end | |
class << self | |
def greet | |
"meta-singleton parent" | |
end | |
# if the method were not defined above, the call would not propagate up | |
# the singleton class chain as there IS no singleton class | |
# chain in the context of belonging to the same singleton object. | |
# | |
# In effect, this makes singleton method lookup parallel and really | |
# nice and easy | |
class << self | |
def greet | |
"meta-meta-singleton parent" | |
end | |
end | |
end | |
end | |
end | |
class Child < Parent | |
end | |
p Child.greet | |
p Child.singleton_class.greet #see line 17 | |
p Child.singleton_class.singleton_class.greet | |
p Parent.singleton_methods | |
p Parent.singleton_class.singleton_methods | |
p Parent.singleton_class.singleton_class.singleton_methods | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment