Your beliefs about how this works seem correct, but I'm not sure why you think this is not working.
In Ruby 1.8.7:
irb> a = Class.new.methods - Object.new.methods => [... 36 element array ...] irb> b = Class.methods - Object.new.methods => [... 37 element array ...] irb> b - a => ["nesting"]
A regular class instance (Class.new) has 36 instance methods. If I look at the class itself, which is also an ordinary instance of the class, it has the same 36 instance methods, plus 1 additional class method (nesting), which exists only because it is inherited from its superclass module.
Note that adding an instance method to a class automatically adds it as a class method, but adding a class to a metaclass class will not.
irb> class Class ; def everywhere ; true ; end ; end irb> class << Class ; def only_singleton ; true ; end ; end irb> Class.everywhere => true irb> Class.new.everywhere => true irb> Class.only_singleton => true irb> Class.new.only_singleton NoMethodError: undefined method 'only_in_singleton' for
source share