Skip to content

Instantly share code, notes, and snippets.

@xumingyong
Created February 13, 2012 01:57
Show Gist options
  • Select an option

  • Save xumingyong/1812724 to your computer and use it in GitHub Desktop.

Select an option

Save xumingyong/1812724 to your computer and use it in GitHub Desktop.
Ruby: meta-programming
#definition
class Object < BasicObject
include Kernel
...
end
#examples
module M; end
class C; include M; end
C.ancestors # => [M, Object, Kernel, BasicObject]
#eigenclass, metaclass or sington class is a hidden class for each object,
#which only have one instance, where sington methods lives.
#use following to define singleton class.
class << self; self; end
#1. superclass of metaclass of object is object's class
#2. superclass of metaclass of class is metaclass of class's superclass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment