Skip to content

Instantly share code, notes, and snippets.

@luke-gru
Created August 22, 2011 19:59
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 luke-gru/1163364 to your computer and use it in GitHub Desktop.
Save luke-gru/1163364 to your computer and use it in GitHub Desktop.
#!/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