Eigenclass in Ruby

References:

  1. When creating singleton methods (i.e. def self.foo) Ruby will create an anonymous class to hold these methods. The anonymous class then assumes the role of the object’s class and the original class is re-designated as the superclass of that anonymous class (Eigenclass).

  2. private is actually a method

  3. private method only changes the visibility of instance methods

  4. Class methods on the other hand are instance methods of the Eigenclass

 1class Test
 2
 3	def self.bar
 4		puts "bar"
 5	end
 6
 7	def self.foo
 8		puts "foo"
 9	end
10
11	private_class_method :foo, :bar
12
13end
14
15Test.bar
16Test.foo