Skip to content

Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

Class#inherited

inherited(subclass)

Callback invoked whenever a subclass of the current class is created.

Example:

Example
class Foo
  def self.inherited(subclass)
    puts "New subclass: #{subclass}"
  end
end

class Bar < Foo
end

class Baz < Bar
end

produces:

Example
New subclass: Bar
New subclass: Baz
See also #attached_object #json_creatable? #allocate #new also in 4.1 · 4.0 · 3.4 · 3.2 · 3.1 · 3.0