Skip to content

Instantly share code, notes, and snippets.

@xpepper
Created April 22, 2012 22:45
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 xpepper/2467371 to your computer and use it in GitHub Desktop.
Save xpepper/2467371 to your computer and use it in GitHub Desktop.
Class method lookup
class Parent
class << self
def who_am_i
puts "I'm #{self}"
end
def singleton
class << self; self; end
end
end
end
class Child < Parent
end
c = Child.singleton
until c.nil? do
puts c.to_s
c = c.superclass
end
#=> #<Class:Child>
#=> #<Class:Parent>
#=> #<Class:Object>
#=> #<Class:BasicObject>
#=> Class
#=> Module
#=> Object
#=> BasicObject
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment