Skip to content

End of Life Ruby 3.1 has reached end of life and gets no more fixes. 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 #allocate #json_creatable? .new #new also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.0