RubyMine 2021.3 Help

Extract superclass

The Extract Superclass refactoring allows you to extract certain members from a selected class into a new base class. The original class will be inherited from the created base class.

To extract a superclass:

  1. Place a caret at a class name or any place within a class.

  2. Select Refactor | Extract/Introduce | Superclass from the main menu.

  3. In the Extract Superclass dialog, specify the superclass name, a directory where it should be placed, and select members to be added:

    Extract Superclass dialog

    Click OK. RubyMine will create a superclass in a separate file.

Example

# 'cat.rb' file class Cat def breathe puts "inhale and exhale" end def speak puts "Meow" end end
# 'cat.rb' file require_relative 'mammal.rb' class Cat < Mammal def speak puts "Meow" end end # # 'mammal.rb' file class Mammal < Object def breathe puts "inhale and exhale" end end
Last modified: 26 August 2021