提取超类
提取超类重构允许您将选定类中的某些成员提取到一个新的基类中。 原始类将继承自创建的基类。
要提取超类:
将插入符号放置在类名或类中的任意位置。
从主菜单中选择 。
在 提取超类 对话框中,指定超类名称、应放置的目录,并选择要添加的成员:

点击 确定。 RubyMine 将在单独的文件中创建一个超类。
示例
# '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
最后修改日期: 2025年 9月 26日