Inheritance of Singleton Class

suggest change

Subclassing also Subclasses Singleton Class

class Example
end

Example.singleton_class #=> #<Class:Example>

def Example.foo
  :example
end

class SubExample < Example
end

SubExample.foo #=> :example

SubExample.singleton_class.superclass #=> #<Class:Example>

Extending or including a module does not copy its singleton methods

module ExampleModule
end

def ExampleModule.foo
  :foo
end

class Example
  extend ExampleModule
  include ExampleModule
end

Example.foo #=> NoMethodError: undefined method 'foo' for class Example

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents